Format
#include <string.h> int strcoll(const char *string1, const char *string2);
Language Level: ANSI, XPG4
strcoll compares two strings using the collating sequence
specified by the program's locale.
Return Value
strcoll returns a value indicating the relationship
between the strings, as listed below:
| Value | Meaning |
| Less than 0 | string1 less than string2 |
| 0 | string1 equivalent to string2 |
| Greater than 0 | string1 greater than string2 |
Example
This example compares the two strings passed to main.
#include <stdio.h> #include <string.h>
int main(int argc, char ** argv)
{
int result;
if ( argc != 3 )
{
printf( "Usage: %s string1 string2\n", argv[0] );
}
else
{
result = strcoll( argv[1], argv[2] );
if ( result == 0 )
printf( "\"%s\" is identical to \"%s\"\n", argv[1], argv[2] );
else if ( result < 0 )
printf( "\"%s\" is less than \"%s\"\n", argv[1], argv[2] );
else
printf( "\"%s\" is greater than \"%s\"\n", argv[1], argv[2] );
}
/*****************************************************************
If the program is passed the following arguments:
"firststring" "secondstring"
The output should be:
"firststring" is less than "secondstring"
*****************************************************************/
}
![]()
setlocale -- Set Locale
strcmp -- Compare Strings
strcmpi -- Compare Strings Without
Case Sensitivity
strncmp -- Compare Strings
wcscoll -- Compare Wide-Character
Strings
<string.h>