I'm using Bloodshed Dev-C (this is MinGW/GCC i think). Yeah, 'I' should be decreased by one. I made it work using strlen, but using strcmp still doesn't work for. Language Level: Extension. Threadsafe: Yes. Locale Sensitive: The behavior of this function might be affected by the LCCTYPE category of the current locale.For more information, see Understanding CCSIDs and Locales. Stricmp compares string1 and string2 without sensitivity to case. All alphabetic characters in the two arguments string1 and string2 are.
The function strcmp() is a built-in library function and it is declared in “string.h” header file. This function is used to compare the string arguments. It compares strings lexicographically which means it compares both the strings character by character. It starts comparing the very first character of strings until the characters of both strings are equal or NULL character is found.
If the first character of both strings are equal, it checks second character and so on. This process will be continued until NULL character is found or both characters are unequal.
Here is the syntax of strcmp() in C language,
This function returns the following three different values based on the comparison.
1.Zero(0) − It returns zero if both strings are identical. All characters are same in both strings.
Here is an example of strcmp() when both strings are equal in C language,
2. Greater than zero(>0) − It returns a value greater than zero when the matching character of left string has greater ASCII value than the character of the right string.
Here is an example of strcmp() when it returns greater than zero value in C language,
3. Less than zero(<0) − It returns a value less than zero when the matching character of left string has lesser ASCII value than the character of the right string.
Here is an example of strcmp() in C language
Here, we have to create a strcmp (string compare) function that compares two string but ignores cases of the characters of the string. The function will return -1 if string1 < string2, 0 if string1 = string2, 1 if string1 > string2.
Let’s take an example to understand the problem,
To create our own strcmp function that ignores cases while comparing the strings. We will iterate through all characters of both the strings, if characters at ith index are the same i.e. string1[i] string2[i], continue. If string1[i] > string2[i], return 1. If string1[i] < string2[i], return -1. If the string ends returns 0.
Here, we have to ignore cases, so A and a will be considered the same. We will use the ASCII values of the characters, then ASCII for a = 97 will be equal to ASCII of A = 65.
Program to show the implementation of our solution,