wcschr Function

Locates the first occurrence of a wide character in 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);

Arguments

s
the wide string in which to search
c
the wide character to search for

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 wide string pointed to by s. The terminating null wide character is searchable.

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 wc1 = L'm', wc2 = L'y';
  wchar_t *ptr;
  int res;

  wprintf(L"ws : %ls\n\n", ws);

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

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

Example Output

ws : What time is it?

m found at position 8

y not found