Name

wcspbrk

Synopsis

Finds the first wide character in a string that matches any wide character in another string

#include <wchar.h>
wchar_t *wcspbrk( const wchar_t *s1, const wchar_t *s2 );

The wcspbrk() function returns a pointer to the first wide character in the string addressed by s1 that matches any wide character contained in the string addressed by s2. If the two strings have no wide characters in common, then wcspbrk() returns a null pointer.

Example

wchar_t *story = L"He shouted: \"What? I can't hear you!\"\n";
wchar_t separators[ ] = L" \t\n.:?!\"";
wchar_t *start = story, *end = NULL;
wchar_t words[16][16];
int i = 0;

while ( i < 16 && ( end = wcspbrk( start, separators ) ) != NULL )
{
  if ( end != start )                   // If the separator wasn't the first
  {                                     // character in the substring,
    wcsncpy( words[i], start, end − start );  // then save a word.
    words[i][end − start] = L'\0';            // And terminate it.
    i++;
  }
  start = end + 1;                      // Next wcspbrk call starts with the
}                                       // character after this separator.

fputws( story, stdout );
for ( int j = 0 ; j < i ; j++ )
{
  fputws( words[j], stdout );
  fputwc( L'\n', stdout );
}

See Also

wcschr(), wcsrchr(), wcswcs(), wcscspn(), strpbrk()

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.