function
<cwchar>
wmemcmp
int wmemcmp (const wchar_t* ptr1, const wchar_t* ptr2, size_t num);
Compare two blocks of wide characters
Compares the first num wide characters of the block of memory pointed by ptr1 to the first num wide characters pointed by ptr2, returning zero if they all match or a value different from zero representing which is greater if they do not.
Notice that, unlike wcscmp, the function does not stop comparing after finding a null wide character.
This is the wide character equivalent of memcmp (<cstring>).
Parameters
- ptr1
- Pointer to block of elements of type wchar_t.
- ptr2
- Pointer to block of elements of type wchar_t.
- num
- Number of elemtns of type wchar_t to compare.
Return Value
Returns an integral value indicating the relationship between the content of the blocks:
A zero value indicates that the contents of both memory blocks are equal.
A value greater than zero indicates that the first wide character that does not match in both memory blocks has a greater value in ptr1 than in ptr2; 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 16 17 18 19 20
|
/* wmemcmp example */
#include <wchar.h>
int main ()
{
int a,b;
wchar_t wcs1[20] = L"content by default.";
wchar_t wcs2[20] = 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;
}
|
Output:
wcsncmp comparison: equal
wmemcmp comparison: not equal
|
See also
- memcmp
- Compare two blocks of memory (function
)
- wcscmp
- Compare two strings (function
)
- wcsncmp
- Compare characters of two wide strings (function
)
- wmemchr
- Locate character in block of wide characters (function
)
- wmemcpy
- Copy block of wide characters (function
)
- wmemset
- Fill array of wide characters (function
)