This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>.
All rights reserved.
Released under the GNU General Public License.
strspn
Prototype
#include <string.h>
size_t strspn(const char *s, const char *set);
Description
Returns the length of the maximum initial segment of the string s
which consists entirely of characters from the string set
.
Implementation
#include <string.h>
size_t strspn(const char *s, const char *set)
{
const char *sp1, *sp2;
for (sp1 = s; *sp1 != '\0'; ++sp1)
for (sp2 = set; ; ++sp2)
if (*sp2 == '\0')
return sp1 - s;
else if (*sp1 == *sp2)
break;
return sp1 - s;
}
Example
#include <string.h>
/*
* Return a true value if the argument string is a regular
* decimal number.
*/
int is_number(const char *s)
{
if (strspn(s, "0123456789") == strlen(s))
return 1;
return 0;
}
References
ISO C 9899:1990 7.11.5.6