Home > Electronics Tutorials > C Language Tutorial > string.h - strspn

C Language Programming Library Reference Guide

string.h - strspn

Declaration: size_t strspn(const char *str1, const char *str2); Finds the first sequence of characters in the string str1 that contains any character specified in str2.

Returns the length of this first sequence of characters found that match with str2.



int main(void)
  char string[]="7803 Elm St.";

  printf("The number length is %d.\n",strspn(string,"1234567890"));

  return 0;
The output should be: The number length is 4.
Note: To report broken links or to submit your projects, tutorials please email to Webmaster