1// use: strcmp(string1, string2);
2
3string a = "words";
4string b = "words";
5
6if (strcmp(a, b) == 0)
7{
8 printf("a and b match");
9 // strcmp returns 0 if both strings match
10}
11
12else
13{
14 printf("a and b don't match");
15 // strcmp returns anything else if the strings dont match
16}
1// strCmp implementation
2// string1 < string2 => return a negative integer
3// string1 > string2 => return a positive integer
4// string1 = string2 => return 0
5int strCmp(const char* s1, const char* s2) {
6 while(*s1 && (*s1 == *s2)) {
7 s1++;
8 s2++;
9 }
10 return *s1 - *s2;
11}
1int strncmp(const char *str1, const char *str2, size_t n)
2
3//if Return value < 0 then it indicates str1 is less than str2.
4//if Return value > 0 then it indicates str2 is less than str1.
5//if Return value = 0 then it indicates str1 is equal to str2.