function
<cwchar>
wmemchr
const wchar_t* wmemchr (const wchar_t* ptr, wchar_t wc, size_t num);
wchar_t* wmemchr ( wchar_t* ptr, wchar_t wc, size_t num);
Locate character in block of wide characters
Searches within the first num wide characters of the block pointed by ptr for the first occurrence of wc, and returns a pointer to it (or a null pointer if not found).
Notice that, unlike wcschr, the function does not stop comparing after finding a null wide character.
This is the wide character equivalent of memchr (<cstring>).
Parameters
- ptr
- Pointer to the array of wchar_t elements to be searched.
- wc
- Wide character to be located.
- num
- Number of elements of type wchar_t to compare.
size_t is an unsigned integral type.
Return Value
A pointer to the first occurrence of wc in the array pointed by ptr.
If the wc is not found, the function returns a null pointer.
Portability
In C, this function is only declared as:
wchar_t * wmemchr ( const wchar_t *, wchar_t, size_t );
instead of the two overloaded versions provided in C++.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
/* wmemchr example */
#include <wchar.h>
int main ()
{
wchar_t * pwc;
wchar_t wcs[] = L"Example wide string";
pwc = wmemchr (wcs, L'p', wcslen(wcs));
if (pwc!=NULL)
wprintf (L"'p' found at position %d.\n", pwc-wcs+1);
else
wprintf (L"'p' not found.\n");
return 0;
}
|
Output:
See also
- memchr
- Locate character in block of memory (function
)
- wmemcmp
- Compare two blocks of wide characters (function
)
- wcschr
- Locate first occurrence of character in wide string (function
)
- wcsrchr
- Locate last occurrence of character in wide string (function
)