C Library Function - strcoll()
Description
C Library Function **int strcoll(const char str1, const char str2) Puts the str1 and str2 for comparison, and the result depends on the locale setting of LC_COLLATE.
Declaration
Below is the declaration of the strcoll() function.
int strcoll(const char *str1, const char *str2)
Parameters
- str1 -- the first string to compare.
- str2 -- the second string to compare.
Return Value
The function returns the following values:
- If the return value is < less than 0, it means str1 is less than str2.
- If the return value > 0, it means str2 is less than str1.
- If the return value is = 0, it means str1 is equal to str2.
Example
The following example demonstrates the use of the strcoll() function.
Example
#include
<
stdio.h
#include
<
string.h
int
main
(
)
{
char
str1
[
15
];
char
str2
[
15
]
;
int
ret
;
strcpy
(
str1
,
"
abc
"
)
;
strcpy
(
str2
,
"
ABC
"
)
;
ret
=
strcoll
(
str1
,
str2
)
;
if
(
ret
0
)
{
printf
(
"
str1 is greater than str2
"
)
;
}
else
if
(
ret
<
0
)
{
printf
(
"str2 is less than str1
"
)
;
}
else
{
printf
(
"
str1 equals str2
"
)
;
}
return
(
0
)
;
}
Let's compile and run the above program, which will produce the following result:
str1 大于 str2
C Standard Library -