程序的段错误,core dumped,求帮助!
- C/C++ code
#include<stdio.h>char *Src="/home/haiy/Desktop/tst.data";char *Des="/home/haiy/Desktop/des.data";void main(){ FILE *fp=NULL; char str[100]; /* if(argc<2) printf("Usage:gets_puts <source_file_name> <detination_file_name>!\n"); else{ Src=argv[1]; printf("source file is %s,\n target file is %s\n",Src,Des); } */ printf("This is a tst program!\n"); fp=fopen(Src,"r"); if(fp==NULL) printf("%s open error!\n",Src); else while(feof(fp)==0){ fputs(fgets(str,10,fp),stdout); } fclose(fp);运行在linux下,程序能正常运行,但是总是core dumped,请各位帮忙分析下了。谢谢咯!
[解决办法]
上GDB鸟,闲着不用等发霉啊
[解决办法]
你需要检查一下fgets的返回值
fgets(str,10,fp)
这个可能会返回NULL