wcscoll() — Language collation string comparison

Standards

Standards / Extensions C or C++ Dependencies
ISO C Amendment
XPG4
XPG4.2
C99
Single UNIX Specification, Version 3
both  

Format

#include <wchar.h>

int wcscoll(const wchar_t *wcs1, const wchar_t *wcs2);

General description

Compares the wide-character string pointed to by wcs1 to the wide-character string pointed to by wcs2, both interpreted as appropriate to the LC_COLLATE category of the current locale.

Returned value

wcscoll() returns an integer greater than, equal to, or less than zero, according to whether the wide string pointed to by wcs1 is greater than, equal to, or less than the wide-character string pointed to by wcs2, when both wide-character strings are interpreted as appropriate to the LC_COLLATE category of the current locale.

wcscoll() differs from wcscmp(). wcscoll() function performs a comparison between two wide character strings based on language collation rules as controlled by the LC_COLLATE category. On the other hand, wcscmp() performs a wide-character code to wide-character code comparison.

wcscoll() indicates error conditions by setting errno; however, there is no returned value to indicate an error. To check for errors, errno should be set to zero, and then checked upon return from wcscoll(). If errno is nonzero, an error has occurred.

The EILSEQ error can be set to indicate that the wcs1 or wcs2 arguments contain characters outside the domain of the collating sequence.

Note: The ISO/C Multibyte Support Extensions do not indicate that the wcscoll() function may return with an error.

Example

CELEBW07
/* CELEBW07 */                                   
#include <stdio.h>                                                              
#include <wchar.h>                                                              
                                                                                
int main(void)                                                                  
{                                                                               
   int result;                                                                  
   wchar_t *wcs1 = L"first_wide_string";                                        
   wchar_t *wcs2 = L"second_wide_string";                                       
                                                                                
   result = wcscoll(wcs1, wcs2);                                                
                                                                                
   if ( result == 0)                                                            
      printf("\"%ls\" is identical to \"%ls\"\n", wcs1, wcs2);                  
   else if ( result < 0)                                                        
      printf("\"%ls\" is less than \"%ls\"\n", wcs1, wcs2);                     
   else                                                                         
      printf("\"%ls\" is greater than \"%ls\"\n", wcs1, wcs2);                  
}                                                                               
Output:
"first_wide_string" is less than "second_wide_string"

Related information