Format
#include <strings.h> int srtncasecmp(const char *string1, const char *string2, size_t count);
Language Level: XPG4
Threadsafe: Yes.
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
Thestrncasecmp() function returns a value indicating the relationship between the two strings, as follows:
strncasecmp() |
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
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.