wcscmp() — Compare wide-character strings
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C Amendment |
both |
Format
#include <wchar.h>
int wcscmp(const wchar_t *string1, const wchar_t *string2);
General description
Compares two wide-character strings. The wcscmp() function operates on NULL-terminated wide-character strings. The string arguments to this function must contain a wide NULL character marking the end of the string.
The behavior of this wide-character function is affected by the LC_CTYPE category of the current locale. If you change the category, undefined results can occur.
Returned value
wcscmp() returns a value
indicating the relationship between the two strings, as follows:
- Value
- Meaning
- < 0
- string pointed to by string1 less than string pointed to by string2
- = 0
- string pointed to by string1 identical to string pointed to by string2
- > 0
- string pointed to by string1 greater than string pointed to by string2
Example
CELEBW06
/* CELEBW06
This example compares the wide character string string1 to
string2 using &wcscmp..
*/
#include <stdio.h>
#include <wchar.h>
int main(void)
{
int result;
wchar_t string1[] = L"abcdef";
wchar_t string2[] = L"abcdefg";
result = wcscmp( string1, string2 );
if ( result == 0 )
printf( "\"%ls\" is identical to \"%ls\"\n", string1, string2);
else if ( result < 0 )
printf( "\"%ls\" is less than \"%ls\"\n", string1, string2 );
else
printf( "\"%ls\" is greater than \"%ls\"\n", string1, string2);
}
Output:
"abcdef" is less than "abcdefg"
Related information
- wchar.h
- wcstr.h
- strcmp() — Compare strings
- wcscat() — Append to wide-character string
- wcschr() — Search for wide-character substring
- wcscpy() — Copy wide-character string
- wcscspn() — Find offset of first wide-character match
- wcslen() — Calculate length of wide-character string
- wcsncmp() — Compare wide-character strings