span a string

View versions (4)

INTERFACE

#include <string.h>
size_t strspn ( const char *s, const char *charset )

DESCRIPTION

The strspn function spans the initial part of the null-terminated string &#92;c s as long as the characters from &#92;c s occur in string &#92;c charset.

Example 1
Workings

\code #include <stdio.h> #include <string.h> int main() { char s[20] = "0123456abcde", t[11] = "0123456789"; printf("The position of the first non-digit in s is: %d.
", strspn(s, t)); return 0; } \endcode

Solution

Output:

The position of the first non-digit in s is: 7.

RETURN VALUES

The strspn function returns the number of characters spanned.

SEE ALSO

memchr, strchr, strcspn, strpbrk, strrchr, strstr, strtok

STANDARDS

The strspn function conforms to ISO/IEC 9899:1990 ("ISO C90").