strtok
function uses a static variable for parsing the string into tokens. So this causes a conflict when multiple calls are done. Other than using threads how could I do the following: thx
- Can I use a function pointer to allocate the function at 2 different places? Would this make the static variable inside "strtok" allocate at 2 different places?
//breaking up first by Sentence and than by Word.
char phrase[] = "My dog has fleas.\nAnd he gave them to me.";
char del1[] = "\n";
char del2[] = " ";
char *token1;
char *token2;
token1 = strtok( phrase, del1);
while( token1 != NULL )
{
printf("Sentence: %s",token1);
token2 = strtok( token1, del2);
while( token2 != NULL ){
token2 = strtok( NULL, del2);
printf("WORD: %s",token2);
}
token1 = strtok( NULL, del1);
}