C examples for wchar.h:wmemcmp
function
<cwchar> <wchar.h>
Compare two blocks of wide characters
int wmemcmp (const wchar_t* ptr1, const wchar_t* ptr2, size_t num);
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. |
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.
#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; }