wmemcmp() — Compare wide character

Standards

Standards / Extensions C or C++ Dependencies

ISO C Amendment
C99
Single UNIX Specification, Version 3

both  

Format

Non-XPG4:
#include <wchar.h>

int wmemcmp(const wchar_t * __restrict__s1, 
            const wchar_t * __restrict__s2, size_t n);
XPG4:
#define _XOPEN_SOURCE
#define _MSE_PROTOS
#include <wchar.h>

int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n);

General description

Compares the first n wide chars of the object pointed to by s1 to the first n wide chars of the object pointed to by s2.

If n has the value 0, wmemcmp() returns 0.

Note: The function is now available as a built-in function under ARCH(7) when LP64 is not used.

Special behavior for XPG4: If you define any feature test macro specifying XPG4 behavior before the statement in your program source file to include the wchar header, then you must also define the _MSE_PROTOS feature test macro to make the declaration of the wmemcmp function in the wchar header available when you compile your program. Please see Table 1 for a list of XPG4 and other feature test macros.

Returned value

wmemcmp() returns an integer that is:
< 0
If s1 is less than s2.
= 0
If s1 is equal to s2.
> 0
If s1 is greater than s2.

Example

#include <wchar.h>
#include <stdio.h>

main()
  {
   int      ptr;
   wchar_t  *in  = L"12345678";
   wchar_t  *out = L"12AAAAAB";

   printf("\nGREATER is the expected result");
   ptr = wmemcmp(in, out, 3);
   if (ptr == 0)
        printf("\nArrays are EQUAL %ls %ls \n",in, out);
     else
       {
        if (ptr > 0)
            printf("\nArray %ls GREATER than %ls \n",in, out);
          else
            printf("\nArray %ls LESS than %ls \n",in, out);
       }

  }

Related information