Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C Amendment |
both |
#include <wchar.h>
wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n);
#define _XOPEN_SOURCE
#define _MSE_PROTOS
#include <wchar.h>
wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n);
Locates the first occurrence of the wide character c in the initial n wide chars of the object pointed to by s.
If n has the value 0, wmemchr() finds no occurrence of c and returns a NULL pointer.
Special behavior for XPG4: If you define any feature test macro specifying XPG4 behavior before the statement in your program source file to include the wchar header, then you must also define the _MSE_PROTOS feature test macro to make the declaration of the wmemchr() function in the wchar header available when you compile your program. See Table 1 for a list of XPG4 and other feature test macros.
If successful, wmemchr() returns a pointer to the first occurrence of the wide character c in object s.
If the wide character c does not occur within the first n wide characters of s, wmemchr() returns the NULL pointer.
#include <stdio>
#include <wchar>
main()
{
wchar_t *in = L"1234ABCD";
wchar_t *ptr;
wchar_t fnd = L'A';
printf("\nEXPECTED: ABCD");
ptr = wmemchr(in, L'A', 6);
if (ptr == NULL)
printf("\n** ERROR ** ptr is NULL, char L'A' not found\n");
else
printf("\nRECEIVED: %ls \n",ptr);
}