my strpbrk

hi guys.
this is an example of 'for' and 'while' using together
i'm beginner in C/C++ if it's better way please tell me

for see original strpbrk go to here:
http://www.cplusplus.com/reference/cstring/strpbrk/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
char * mystrpbrk ( const char * __s1, const char * __s2) {
    for (;  *__s1  ; __s1++) {
        char * tempS1 = (char*)__s1;
        char * tempS2 = (char*)__s2;
        
        while(*tempS2) {
            if (tempS1[0] == tempS2[0]) {
                return tempS1;
            }
            tempS2++;
        }
    }
    return NULL;
}


test app

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main ()
{
    char str[] = "Sadegh Hajizadeh";
    char key[] = "aeoiu";
    char * pch;
    printf ("'%s' Vowels in '%s': ",key ,str);
    pch = mystrpbrk(str, key);
    //cout << "\nPCH= " << pch << endl;
    while (pch != NULL)
    {
        printf ("%c " , *pch);
        pch = mystrpbrk( pch+1 ,key);
    }
    printf ("\n");
    return 0;
}


output :

'aeoiu' Vowels in 'Sadegh Hajizadeh': a e a i a e 
Last edited on
You could `return' in line 8
You could simply cast the result

IIRC names with two leading underscore are reserved for the compiler
but i like use two leading underscore in my function or classes
it's make problem ??!! or any thing better i don't use underscore?

sorry for my english
Last edited on
Topic archived. No new replies allowed.