Format
#include <string.h> int strnicmp(const char *string1, const char *string2, int n);
Language Level: Extension
Threadsafe: Yes.
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:
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.