爲什麼會出現段錯誤使用此代碼?
void test(char *data)
{
char *pch;
pch = strtok(data, " ,.-"); // segfault
while (pch != NULL)
{
printf("%s\n", pch);
pch = strtok(NULL, " ,.-");
}
return NULL;
}
char *data = "- This, a sample string.";
test(data);
這已經被問[多](http://stackoverflow.com/questions/2385697/strtok-giving-segmentation-fault)[次](HTTP:// stackoverflow.com/questions/5925405/problem-with-strtok-and-segmentation-fault)[before](http://stackoverflow.com/questions/272876/cs-strtok-and-read-only-string-literals) 。 –