6.23.43 wcspbrk Function

Search a wide string for the first occurrence of a wide character from a specified set of wide characters.

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

Include

<wchar.h>

Prototype

wchar_t *wcspbrk(const wchar_t * s1, const wchar_t * s2);

Arguments

s1
the wide string in which to search
s2
the wide characters to search for

Return Value

Returns a pointer to the matched wide character in s1 if found; otherwise, returns a null pointer.

Remarks

This function will search s1 for the first occurrence of a character contained in s2.

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 ws1[20] = L"What time is it?";
  wchar_t ws2[20] = L"xyz";
  wchar_t ws3[20] = L"eou?";
  wchar_t *ptr;
  int res;

  wprintf(L"wcspbrk(\"%ls\", \"%ls\")\n", ws1, ws2);
  ptr = wcspbrk(ws1, ws2);
  if (ptr != NULL)
  {
    res = ptr - ws1 + 1;
    wprintf(L"match found at position %d\n", res);
  }
  else
    wprintf(L"match not found\n");
  wprintf(L"\n");

  wprintf(L"wcspbrk(\"%ls\", \"%ls\")\n", ws1, ws3);
  ptr = wcspbrk(ws1, ws3);
  if (ptr != NULL)
  {
    res = ptr - ws1 + 1;
    wprintf(L"match found at position %d\n", res);
  }
  else
    wprintf(L"match not found\n");
}

Example Output

wcspbrk("What time is it?", "xyz")
match not found

wcspbrk("What time is it?", "eou?")
match found at position 9