Count the characters at the beginning of a string that are in a given character set
#include <string.h> size_t strspn( const char* str, const char* charset );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The strspn() function computes the length of the initial segment of the string pointed to by str that consists of characters from the string pointed to by charset. The terminating null character isn't considered to be part of charset.
The length of the segment.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main( void ) { printf( "%d\n", strspn( "out to lunch", "aeiou" ) ); printf( "%d\n", strspn( "out to lunch", "xyz" ) ); return EXIT_SUCCESS; }
produces the output:
2 0
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |