当我运行这段代码时,它给出了一个段错误。
main ()
{
char *line ="2,3,22";
int size=3,i,j;
double value;
char *val;
for (i = 0; i<size ; i++) {
if (line == NULL) break;
printf("%s\n",strtok (line ,","));
}
}
并给了一个
"warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=] printf("%s\n",strtok (line ,","));"
因此,当我将 strtok
值分配给 char* 时,它给出了一个错误。为什么 strtok
返回一个 int 值?解决方案是什么?
最佳答案
它使用 strtok
的隐式原型(prototype).你需要 #include <string.h>
(您可能还需要为 stddef.h
添加 NULL
,并且还应为 stdio.h
添加 printf
。
关于c - strtok在c中返回int类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43031926/