Format
#include <string.h>
int strnicmp(const char *string1, const char *string2, int n);
Language Level: Extension
Threadsafe: Yes.
Locale Sensitive: The behavior of this function might be affected by the LC_CTYPE category of the current locale. For more information, see Understanding CCSIDs and Locales.
Description
strnicmp compares, at most, the first n characters of string1 and string2 without sensitivity to case.
The function operates on null terminated strings. The string arguments to the function are expected to contain a null character (\0) marking the end of the string.
Return Value
strnicmp returns a value indicating the relationship between the substrings, as follows:
Example that uses strnicmp()
This example uses strnicmp to compare two strings.
#include <stdio.h>
#include <string.h>
int main(void)
{
char *str1 = "THIS IS THE FIRST STRING";
char *str2 = "This is the second string";
int numresult;
/* Compare the first 11 characters of str1 and str2
without regard to case */
numresult = strnicmp(str1, str2, 11);
if (numresult < 0)
printf("String 1 is less than string2.\n");
else
if (numresult > 0)
printf("String 1 is greater than string2.\n");
else
printf("The two strings are equivalent.\n");
return 0;
}
The output should be:
The two strings are equivalent.
Related Information: