Strcspn
int strcspn(char *str1, char *str2)
{
    int cnt = 0;
    char *s1, *s2;
 
    for (s1 = str1; *s1 != '\0'; s1++, cnt++) {
        for (s2 = str2; *s2 != '\0'; s2++)
            if (*s1 == *s2)
                return cnt;   //break doesn't work, only break one for loop
    }
    return cnt;    // cnt == length(str1)
}
 
int main ()
{
    char str[] = "fcba73";
    char keys[] = "1234567890";
    int i;
    i = strcspn(str,keys);
    printf ("The first number in str is at position %d.\n",i+1);
    return 0;
}

Output:

The first number in str is at position 5.

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