function
<cwchar>

wcscmp

int wcscmp (const wchar_t* wcs1, const wchar_t* wcs2);
Compare two strings
Compares the C wide string wcs1 to the C wide string wcs2.

This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminating null wide character is reached.

This function performs a simple comparison of the wchar_t values, without taking into account locale-specific rules (see wcscoll for a similar function that does).

This is the wide character equivalent of strcmp (<cstring>).

Parameters

wcs1
C wide string to be compared.
wcs2
C wide string to be compared.

Return Value

Returns an integral value indicating the relationship between the wide strings:
A zero value indicates that both are considered equal.
A value greater than zero indicates that the first wide character that does not match has a greater value in wcs1 than in wcs2; And a value less than zero indicates the opposite.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* wcscmp example */
#include <stdio.h>
#include <wchar.h>

int main ()
{
  wchar_t wsKey[] = L"apple\n";
  wchar_t wsInput[80];
  do {
     wprintf (L"Guess my favourite fruit? ");
     fgetws (wsInput,80,stdin);
  } while (wcscmp (wsKey,wsInput) != 0);
  fputws (L"Correct answer!",stdout);
  return 0;
}


Possible output:

Guess my favourite fruit? orange
Guess my favourite fruit? apple
Correct answer!

See also