Strspn
int strspn(char *str1, char *str2)
{
    char *s1, *s2;
    int cnt = 0;
 
    for (s1 = str1, s2 = str2; *s1 != '\0' && *s2 != '\0'; s2++) { // s2 ++ every time
        if (*s1 == *s2) {
            cnt++;
            s1++;         // s1 ++ only when matched char is found
        }
    }
    return cnt;
}
 
int main()
{
    int i;
    char strtext[] = "129th";
    char cset[] = "1234567890000t";
 
    i = strspn (strtext,cset);
    printf ("The length of initial number is %d.\n",i);
    return 0;
}

Output:

The length of initial number is 4.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License