Syntax
#include <wchar.h> int wcscoll(const wchar_t *wcstr1, const wchar_t *wcstr2);Description
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. If a string will be collated many times, as when inserting an entry into a sorted list, wcsxfrm followed by wcscmp can be more efficient.
wcscoll returns an integer value indicating the relationship between the strings, as listed below: compact break=fit.
Value
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.
This example uses wcscoll to compare two wide-character strings.
#include <wchar.h>#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
wchar_t *wcs1 = L"A wide string";
wchar_t *wcs2 = L"a wide string";
int result;
if (NULL == setlocale(LC_ALL, "Ja_JP")) {
printf("setlocale failed.\n");
exit(EXIT_FAILURE);
}
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 identical to "a wide string"
****************************************************************************/
}
Related Information