首页 > 解决方案 > strtok 函数 const char 指针错误

问题描述

我不断收到以下错误

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

标签: c

解决方案


strtok需要对您的字符串进行更改,因此它不能对const char*参数进行操作。您需要先复制该字符串,然后再将其发送到strtok.


推荐阅读