Name
wcscmp
Synopsis
Compares two wide strings
#include <wchar.h> intwcscmp
( const wchar_t *s1
, const wchar_t *s2
);
The wcscmp()
function
compares the wide strings addressed by its two pointer arguments,
and returns a value indicating the result as follows:
- Zero
The two strings are equal.
- Greater than zero
The string addressed by
s1
is greater than the string addressed bys2
.- Less than zero
The string addressed by
s1
is less than the string addressed bys2
.
The wcscmp()
function
compares the strings one wide character at a time. As soon as it
finds unmatched characters in corresponding positions in the two
strings, the string containing the greater wide character value at
that position is the greater string.
Example
int result = 0;
wchar_t word1[255], word2[256], *greaterlessequal;
while ( result < 2 )
{
fputws( L"Type two words, please: ", stdout );
result = wscanf( L"%255l[^ ]%255ls", word1, word2 );
if ( result == EOF )
return EOF;
}
result =wcscmp
( word1, word2 );
if ( result < 0 )
greaterlessequal = L"less than";
else if ( result > 0 )
greaterlessequal = L"greater than";
else
greaterlessequal = L"the same as";
wprintf( L"The word \"%ls\" is %ls the word \"%ls\".\n", word1,
greaterlessequal, word2 );
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.