Compare commits
2 Commits
747fc905b5
...
f97d402b17
Author | SHA1 | Date | |
---|---|---|---|
f97d402b17 | |||
14316263bd |
@ -1 +1,34 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
int strcmp(char s1[], char s2[]) {
|
||||
int i = 0;
|
||||
while (s1[i] != '\0' && s2[i] != '\0') {
|
||||
if (s1[i] != s2[i]) {
|
||||
return s1[i] - s2[i];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
if (s1[i] == '\0' && s2[i] == '\0') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return s1[i] - s2[i];
|
||||
}
|
||||
|
||||
int main() {
|
||||
char str1[] = "Hello";
|
||||
char str2[] = "Hello";
|
||||
char str3[] = "World";
|
||||
|
||||
// Пример 1
|
||||
printf("strcmp(\"%s\", \"%s\") = %d\n", str1, str2, strcmp(str1, str2));
|
||||
// Пример 2
|
||||
printf("strcmp(\"%s\", \"%s\") = %d\n", str1, str3, strcmp(str1, str3));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user