wmemcmp - C wchar.h

C examples for wchar.h:wmemcmp

Type

function

From


<cwchar>
<wchar.h>

Description

Compare two blocks of wide characters

Prototype

int wmemcmp (const wchar_t* ptr1, const wchar_t* ptr2, size_t num);

Parameters

Parameter Description
ptr1 Pointer to the first block in type wchar_t.
ptr2 Pointer to the second block in type wchar_t.
num Number of elements in type wchar_t to compare.

Return Value

0 indicates that the contents of both memory blocks are equal.

>0 indicates that the first wide character has a greater value in ptr1 than in ptr2.

<0 indicates that the first wide character has a less value in ptr1 than in ptr2.

Demo Code


#pragma warning(disable:4996)/*from w  w  w.  j  av a2  s .  c  om*/
#define _CRT_SECURE_NO_WARNINGS

#include <wchar.h>

int main()
{
  int a, b;
  wchar_t wcs1[] = L"this is a test test.";
  wchar_t wcs2[] = L"-------------------";

  wcscpy(wcs1, L"test string");
  wcscpy(wcs2, L"test string");

  a = wcsncmp(wcs1, wcs2, 20);  /* compares 12 characters (until L'\0') */
  b = wmemcmp(wcs1, wcs2, 20);  /* compares 20 characters */

  wprintf(L"wcsncmp comparison: %ls\n", a ? L"not equal" : L"equal");
  wprintf(L"wmemcmp comparison: %ls\n", b ? L"not equal" : L"equal");

  return 0;
}

Related Tutorials