Name

wcscspn

Synopsis

Searches for any element of one wide string in another

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

The wcscspn() function returns the number of wide characters at the beginning of the string addressed by s1 that do not match any of the wide characters in the string addressed by s2. In other words, wcscspn() returns the index of the first wide character in s1 that matches any wide character in s2. If the two strings have no wide characters in common, then the return value is the length of the string addressed by s1.

Example

wchar_t *path = L"/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games";
int  separator;

wchar_t *basename = L"aprogram";
wchar_t fullname[1024] = L"";

separator =wcscspn( path, L":" );

if ( separator > ( sizeof(fullname) − 1 ))
  return −1;

wcsncpy( fullname, path, separator );
fullname[separator] = '\0';
wcsncat( fullname, L"/", sizeof(fullname) − wcslen(fullname) −1 );
wcsncat( fullname, basename, sizeof(fullname) − wcslen(fullname) −1 );

fputws( fullname, stdout );

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.