Strpbrk
char *strpbrk(char *str1, char *str2)
{
    char *p1, *p2;
 
    for (p1 = str1; *p1 != '\0'; p1++) { // scan through str1
        for (p2 = str2; *p2 != '\0'; p2++) {  // find matched char in str2 for current char in str1
            if (*p1 == *p2)          // if find out, direct return current position of str1
                return p1;
        }
    }
    return NULL;    // p1 == '\0'. so can't find anything
}
int main ()
{
    char str[] = "This is a sample string";
    char key[] = "aeiou";
    char * pch;
    printf ("Vowels in '%s': ",str);
    pch = strpbrk(str, key);
    while (pch != NULL)
    {
        printf ("%c " , *pch);
        pch = strpbrk(pch+1,key);
    }
    printf ("\n");
    return 0;
}

Output:

Vowels in 'This is a sample string': i i a a e i

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