Compare commits

...

2 Commits

Author SHA1 Message Date
f97d402b17 Merge pull request 's1' (#1) from vetka1 into main
Reviewed-on: #1
2024-11-26 19:56:16 +04:00
14316263bd commit 2 2024-11-26 19:54:14 +04:00

View File

@ -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;
}