strtok wont accept: char *str
- by bks
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:\n",str);
pch = strtok (str,delims);
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, delims);
}
return 0;