原则:在源文件中没有发现函数的声明,可能是忘加头文件了。(未经声明的函数原型一律默认为返回int值)
不要忽视Warning错误
以下代码在CodeBlock中可以正常编译执行
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
int main()
{
char s[] = "hello|world|ecnu";
char *delim = "|";
char *p;
p = strtok(s, delim);
while(p)
{
printf("%s\n",p);
p = strtok(NULL, delim);
}
return 0;
}
编译结果
执行结果
但在linux平台下编译运行发生段错误(Segmentation fault (core dumped))
编译结果
执行结果
加入-Wall编译
最终发现没有加头文件 #include <string.h>