function
<cwchar>
wcsncmp
int wcsncmp (const wchar_t* wcs1, const wchar_t* wcs2, size_t num);
Compare characters of two wide strings
Compares up to num characters of the C wide string wcs1 to those of the C wide string wcs2.
This function starts comparing the first character of each wide string. If they are equal to each other, it continues with the following pairs until the characters differ, until a terminating null wide character is reached, or until num characters match in both strings, whichever happens first.
This is the wide character equivalent of strncmp (<cstring>).
Parameters
- wcs1
- C wide string to be compared.
- wcs2
- C wide string to be compared.
- num
- Maximum number of characters to compare.
size_t is an unsigned integral type.
Return Value
Returns an integral value indicating the relationship between the wide strings:
A zero value indicates that the characters compared in both strings form the same string.
A value greater than zero indicates that the first 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 16
|
/* wcsncmp example */
#include <stdio.h>
#include <string.h>
int main ()
{
wchar_t wcs[][5] = { L"R2D2" , L"C3PO" , L"R2A6" };
int n;
wprintf (L"Looking for R2 astromech droids...\n");
for (n=0 ; n<3 ; n++)
if (wcsncmp (wcs[n],L"R2xx",2) == 0)
{
wprintf (L"found %ls\n",wcs[n]);
}
return 0;
}
|
Output:
Looking for R2 astromech droids...
found R2D2
found R2A6
|
See also
- strncmp
- Compare characters of two strings (function
)
- wcscmp
- Compare two strings (function
)
- wmemcmp
- Compare two blocks of wide characters (function
)
- wcsrchr
- Locate last occurrence of character in wide string (function
)
- wcsspn
- Get span of character set in wide string (function
)