strspn


strspn

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

 #include <string.h> int strspn ( const char *s1 , const char *s2  ); 

The strspn( ) function returns the index of the first character in the string addressed by s1 that does not match any character in the string addressed by s2, or in other words, the length of the string segment addressed by s1 that contains only characters that are present in the string addressed by s2. If all characters in s1 are also contained in s2, then strspn( ) returns the index of s1's string terminator character, which is the same as strlen(s1).

Example

 char wordin[256]; double val; puts( "Enter a floating-point number, please:" ); scanf( "%s", wordin ); int index = strspn( wordin, "+-0123456789eE." ); if ( index < strlen( wordin ) )   printf( "Sorry, but the character %c is not permitted.\n",            wordin[index] ); else {   sscanf( wordin, "%lg", &val );   printf( "You entered the value %g\n", val ); } 

See Also

strcspn( ), wcsspn( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net