diff --git a/main/main.cpp b/main/main.cpp index 5f28270..39c6cf4 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1 +1,34 @@ - \ No newline at end of file +#include + + +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; +} \ No newline at end of file