#include <string.h> size_t strspn(const char *str, const char *cset);
strspn
locates the first character in the argument string str
not contained in the argument string cset
, returning its position
in str
.
strspn
returns the number of consecutive characters in the character
set cset
found in the argument string str
, starting
at the first character in str
. If all characters of the string
are in the set (so that no character not in the set is found), the
value returned is the length of the string. If the character set is
null (that is, if it contains no characters), the return value from
strspn
is 0.
See the memscntb
function description for information on possible
interactions between the strspn
, memscntb
, or
strscntb
functions.
#include <string.h> #include <stdio.h> #define MAXLINE 40 main() { char line[MAXLINE]; char *word; size_t a,b; puts("Enter a word (only alphabetic characters):"); word = gets(line); /* Find the position of the first character */ /* in the word that is not a vowel. */ a = strspn(word, "aeiou"); /* Find the position of the first character */ /* in the word that is not a consonant. */ b = strspn(word, "bcdfghjklmnpqrstvwxyz"); printf("The first consonant in the given word is: %cn", word[a]); printf("The first vowel in the given word is: %cn", word[b]); }
strcspn
, strrspn
, strscan
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.