We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 44c485b commit 556cfe5Copy full SHA for 556cfe5
user/string.c
@@ -10,26 +10,22 @@
10
*/
11
int strcmp(const char *str_1, const char *str_2)
12
{
13
- unsigned char str1, str2;
14
- while(1)
15
- {
16
- str1 = *str_1++;
17
- str2 = *str_2++;
18
-
19
- if (str1 != str2)
20
21
- // NOTE: If needed in the future, can return the difference between
22
- // the strings rather than just -1 or 1
23
- return str1 < str2 ? -1 : 1;
24
- }
+ unsigned char ch1, ch2;
+ do
+ {
+ ch1 = *str_1++;
+ ch2 = *str_2++;
25
26
- if (!str1)
27
28
- break;
29
+ if (ch1 != ch2)
+ // NOTE: If needed in the future, can return the difference between
+ // the strings rather than just -1 or 1
+ return ch1 < ch2 ? -1 : 1;
30
}
31
32
- return 0;
+ } while (ch1);
+
+ return 0;
33
34
35
/**
0 commit comments