labarat6/main/main.cpp
2024-11-26 19:54:14 +04:00

34 lines
621 B
C++

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