Format
#include <wchar.h> int wcscoll(const wchar_t *wcstr1, const wchar_t *wcstr2);
Language Level: ANSI 93, XPG4
wcscoll compares the wide-character string pointed to by wcstr1
to the wide-character string pointed to by wcstr2,
both interpreted according to the information in the LC_COLLATE
category of the current locale.
wcscoll differs from the wcscmp function. wcscoll performs a comparison between two wide-character strings based on language collation rules as controlled by the LC_COLLATE category. In contrast, wcscmp performs a wide-character code to wide-character code comparison.
Return Value
wcscoll returns an integer value indicating the
relationship between the strings, as listed below:
| Value | Meaning |
| Less than 0 | wcstr1 less than wcstr2 |
| 0 | wcstr1 equivalent to wcstr2 |
| Greater than 0 | wcstr1 greater than wcstr2 |
On both OS/2 and Windows, if wcs1 or wcs2 contain characters outside the domain of the collating sequence, wcscoll sets errno to EILSEQ.
If an error occurs, wcscoll sets errno to a nonzero value. There is no error return value.
Example
This example uses wcscoll to compare two wide-character
strings.
#include <wchar.h> #include <locale.h> #include <stdio.h> #include <stdlib.h>
#define LOCNAME "ja_jp.ibm-932"
int main(void)
{
wchar_t *wcs1 = L"A wide string";
wchar_t *wcs2 = L"a wide string";
int result;
if (NULL == setlocale(LC_ALL, LOCNAME)) {
printf("Locale \"%s\" could not be loaded\n", LOCNAME);
exit(1);
}
result = wcscoll(wcs1, wcs2);
if (0 == result)
printf("\"%ls\" is identical to \"%ls\"\n", wcs1, wcs2);
else if (0 > result)
printf("\"%ls\" is less than \"%ls\"\n", wcs1, wcs2);
else
printf("\"%ls\" is greater than \"%ls\"\n", wcs1, wcs2);
return 0;
/***********************************************************
The output should be similar to:
"A wide string" is less than "a wide string" ***********************************************************/ }
![]()
strcoll -- Compare Strings Using Collation
Rules
setlocale -- Set Locale
wcscmp -- Compare Wide-Character
Strings
<wchar.h>