wmemchr Function

Locates the first occurrence of a wide character in part of a wide string.

Attention: This function is implemented only by MPLAB XC32 C compilers.

Include

<wchar.h>

Prototype

wchar_t *wcschr(const wchar_t *s, wchar_t c, size_t n);

Arguments

s
the wide string in which to search
c
the wide character to search for
n
the number of wide character to search

Return Value

The function returns a pointer to the wide character, or a null pointer if the wide character was not found.

Remarks

The function locates the first occurrence of the wide character c in the first n wide characters in the wide string pointed to by s.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <wchar.h>

int main(void)
{
  wchar_t ws[50] = L"What time is it?";
  wchar_t ch1 = L'i', ch2 = L'y';
  wchar_t * ptr;
  int res;
  wprintf(L"ws : %ls\n\n", ws);

  ptr = wmemchr(ws, ch1, 50);
  if (ptr != NULL)
  {
   res = ptr - ws + 1;
   wprintf(L"%lc found at position %d\n", ch1, res);
  }
  else
    wprintf(L"%lc not found\n", ch1);
  wprintf(L"\n");

  ptr = wmemchr(ws, ch2, 50);
  if (ptr != NULL)
  {
    res = ptr - ws + 1;
    wprintf(L"%lc found at position %d\n", ch2, res);
  }
  else
    wprintf(L"%lc not found\n", ch2);
}

Example Output

ws : What time is it?

i found at position 7

y not found