strtok wont work correctly when using char *str as the first parameter (not the delimiters string).
Does it have something to do with the area that allocates strings in that notation? (which as far as i know, is a read-only area).
thanks in advance
example:
//char* str ="- This, a sample string."; // <---doesn't work
char str[] ="- This, a sample string."; // <---works
char delims[] = " ";
char * pch;
printf ("Splitting string "%s" into tokens:
",str);
pch = strtok (str,delims);
while (pch != NULL)
{
printf ("%s
",pch);
pch = strtok (NULL, delims);
}
return 0;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…