strtok wont accept: char *str
Posted
by bks
on Stack Overflow
See other posts from Stack Overflow
or by bks
Published on 2010-03-27T15:31:37Z
Indexed on
2010/03/27
15:33 UTC
Read the original article
Hit count: 320
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;
© Stack Overflow or respective owner