wcscmp() — Compare Wide-Character Strings
Format
#include <wchar.h>
int wcscmp(const wchar_t *string1, const wchar_t *string2);
Language Level
ANSI
Threadsafe
Yes
Wide Character Function
See Wide Characters for more information.
Description
The wcscmp()
function
compares two wide-character strings. The wcscmp()
function
operates on null-ended wchar_t strings; string arguments
to this function should contain a wchar_t null character
marking the end of the string. Boundary checking is not performed
when a string is added to or copied.
Return Value
The wcscmp()
function
returns a value indicating the relationship between the two strings,
as follows:
Value | Meaning |
---|---|
Less than 0 | string1 less than string2 |
0 | string1 identical to string2 |
Greater than 0 | string1 greater than string2 |
Example
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 should be similar to: ******************
"abcdef" is less than "abcdefg"
*/
Related Information
- strcmp() — Compare Strings
- strncmp() — Compare Strings
- wcscat() — Concatenate Wide-Character Strings
- wcschr() — Search for Wide Character
- wcscpy() — Copy Wide-Character Strings
- wcscspn() — Find Offset of First Wide-Character Match
- wcslen() — Calculate Length of Wide-Character String
- wcsncmp() — Compare Wide-Character Strings
- __wcsicmp() — Compare Wide Character Strings without Case Sensitivity
- __wcsnicmp() — Compare Wide Character Strings without Case Sensitivity
- <wchar.h>