6.20.11 strcoll Function
Compares one string to another.
Include
<string.h>
Prototype
int strcoll(const char * s1, const char * s2);
Arguments
s1
- first string
s2
- second string
Return Value
Using the locale-dependent rules, it returns a positive number if
s1
is greater than s2
, zero if s1
is equal to s2
or a negative number if s1
is less than
s2
.
Remarks
Compares the two string arguments, subject to the LC_COLLATE
category of
the current locale. When locales are not supported, this function calls
strcmp
.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <string.h>
#include <stdio.h>
#include <locale.h>
int main(void)
{
char buf1[50] = "Where is the time?";
char buf2[50] = "Where did they go?";
int res;
setlocale(LC_CTYPE, "");
printf("buf1 : %s\n", buf1);
printf("buf2 : %s\n", buf2);
res = strcoll(buf1, buf2);
if (res < 0)
printf("buf1 comes before buf2\n");
else if (res == 0)
printf("buf1 and buf2 are equal\n");
else
printf("buf2 comes before buf1\n");
}
Example Output
buf1 : Where is the time?
buf2 : Where did they go?
buf2 comes before buf1