Name

wcsspn

Synopsis

Searches a wide string for a wide character that is not in a given set

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

The wcsspn() function returns the index of the first wide character in the string addressed by s1 that does not match any wide character in the string addressed by s2. In other words, the return value is length of the wide string segment addressed by s1 that contains only wide characters which are present in the wide string addressed by s2. If all of the wide characters in s1 are also contained in s2, then wcsspn() returns the index of s1’s string terminator character, which is the same as wcslen(s1).

Example

wchar_t wordin[256];
double val;
fputws( L"Enter a floating-point number, please:", stdout );
wscanf( L"%ls", wordin );
int index =wcsspn( wordin, L"+-0123456789eE." );
if ( index < wcslen( wordin ) )
  wprintf ( L"Sorry, but the character %lc is not permitted.\n",
           wordin[index] );
else
{
  swscanf( wordin, L"%lg", &val );
  wprintf( L"You entered the value %g\n", val );
}

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.