c str compare code example
Example 1: compare two chars c
strcmp(char, char);
Example 2: c strcmp
// strCmp implementation
// string1 < string2 => return a negative integer
// string1 > string2 => return a positive integer
// string1 = string2 => return 0
int strCmp(const char* s1, const char* s2) {
while(*s1 && (*s1 == *s2)) {
s1++;
s2++;
}
return *s1 - *s2;
}
Example 3: string compare in c
strcmp(leftStr, rightStr);
//compares ascii value and gives positive, negative or zero.