The definition of library function strspn is:

size_t strspn(const char *str, const char *chars)

/*Return number of leading characters at the beginning of the string str which are all members of string chars.*/

e.g. if ‘str’ is “fecxdy” and ‘chars’ is “abcdef” then the function would return 3, since ‘f’, ’e’ and ‘c’ all appear somewhere in ‘chars’, giving 3 leading characters of ‘str’, and ‘x’ is the first character of ‘str’ which is not a member of ‘chars’.

Could someone help me write an implementation of strspn in ‘C’. The only library function I am allowed to call from the implementation is strlen.

>Could someone help me write an implementation of strspn in ‘C’. The only library function I am allowed to call from the implementation is strlen.

Sure, how about this? You start and then post what you have. After that we can give you some suggestions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.