strtok函数const char指针错误

时间:2018-04-28 14:43:36

标签: c

我一直收到以下错误

passing argument 1 of 'strtok' discards 'const' qualifier from pointer target type [enabled by default]

通过这一行

for (char *p = strtok(season_info,"\n"); p != NULL; p = strtok(NULL, " "))

ps:season_info的定义如下:  const char * season_info

1 个答案:

答案 0 :(得分:1)

strtok需要对字符串进行更改,因此无法对const char*参数进行操作。在将该字符串发送到strtok之前,您需要复制该字符串。