Untitled
unknown
plain_text
2 years ago
575 B
7
Indexable
#include <stdio.h>
int ft_strcmp(char *s1, char *s2) {
int result = 0;
while (*s1 != 0 && *s2 != 0) {
if (*s1 != *s2) {
result = (*s1 - *s2);
break;
}
s1++;
s2++;
}
return result;
}
int main() {
char i[] = "abcd";
char j[] = "abzd";
int result = ft_strcmp(i, j);
if (result < 0) {
printf("%s comes before %s", i, j);
} else if (result > 0) {
printf("%s comes after %s", i, j);
} else {
printf("%s and %s are equal", i, j);
}
return 0;
}Editor is loading...