Format
#include <strings.h>
int strncasecmp(const char *string1, const char *string2, size_t count);
Language Level: XPG4
Threadsafe: Yes.
Locale Sensitive: The behavior of this function might be affected by the LC_CTYPE category of the current locale. This function is not available when LOCALETYPE(*CLD) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.
Description
The strncasecmp() function compares up to count characters of string1 and string2 without sensitivity to case. All alphabetic characters in string1 and string2 are converted to lowercase before comparison.
The strncasecmp() 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
The strncasecmp() function returns a value indicating the relationship between the two strings, as follows:
Value | Meaning |
Less than 0 | string1 less than string2 |
0 | string1 equivalent to string2 |
Greater than 0 | string1 greater than string2 |
Example that uses strncasecmp()
This example uses strncasecmp() to compare two strings.
#include <stdio.h>
#include <strings.h>
int main(void)
{
char_t *str1 = "STRING ONE";
char_t *str2 = "string TWO";
int result;
result = strncasecmp(str1, str2, 6);
if (result == 0)
printf("Strings compared equal.\n");
else if (result < 0)
printf("\"%s\" is less than \"%s\".\n", str1, str2);
else
printf("\"%s\" is greater than \"%s\".\n", str1, str2);
return 0;
}
/******** The output should be similar to: ***************
Strings compared equal.
***********************************/
Related Information