很简单的
while((c=fgetc(fp))!=EOF){
if (c=='\t') c=',';
fputc(c, fp2);
}
gcc 编译没报错,为什么执行的时候报段错误,gdb调试报
Program received signal SIGSEGV, Segmentation fault.
0xb7ea521b in getc () from /lib/tls/i686/cmov/libc.so.6
求助!
uname -r
2.6.20-16-generic
[问题] 简单的fgetc fputc为什么运行时报SIGSEGV?
-
- 帖子: 16
- 注册时间: 2007-02-16 15:39
- nobrain
- 帖子: 808
- 注册时间: 2005-08-25 13:58
- 来自: ustc
- 联系:
-
- 帖子: 16
- 注册时间: 2007-02-16 15:39
#include <stdio.h>
FILE *input, *output;
int c;
int main(int argc, char ** argv){
if(argc!=3){
fprintf(stderr,"Usage: %s filename.gpr filename.csv\n", argv[0]);
exit(1);
}
if((input=fopen(argv[1],"r")==NULL)){
fprintf(stderr,"Cannot open %s.", argv[1]);
exit(1);
}
if((output=fopen(argv[2],"w")==NULL)){
fprintf(stderr,"Cannot write to %s\n", argv[2]);
exit(1);
}
while((c=fgetc(input))!=EOF){
if (c == '\t') c=',';
fputc(c,output);
}
fclose(input);
fclose(output);
return 0;
}
FILE *input, *output;
int c;
int main(int argc, char ** argv){
if(argc!=3){
fprintf(stderr,"Usage: %s filename.gpr filename.csv\n", argv[0]);
exit(1);
}
if((input=fopen(argv[1],"r")==NULL)){
fprintf(stderr,"Cannot open %s.", argv[1]);
exit(1);
}
if((output=fopen(argv[2],"w")==NULL)){
fprintf(stderr,"Cannot write to %s\n", argv[2]);
exit(1);
}
while((c=fgetc(input))!=EOF){
if (c == '\t') c=',';
fputc(c,output);
}
fclose(input);
fclose(output);
return 0;
}
-
- 帖子: 16
- 注册时间: 2007-02-16 15:39
t$ ls
2007-07-06_liang-heart-s5-800_0635_R1.jpg gpr2csv.py
2007-07-06_liang-heart-s5-800_0635_W1.jpg gpr2cvs.c
2007-07-06_liang-heart-s5-800_labeled.jpg gpr2cvs.c~
data.gpr liang-heart-s5-800_635.tif
g2c
liang@liang-dv1381tu:~/Documents/Experiments/Ana-with-GenePix/liang20070706/heart$ gdb g2c
GNU gdb 6.6-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) set args data.gpr data.csv
(gdb) r
Starting program: /home/liang/Documents/Experiments/Ana-with-GenePix/liang20070706/heart/g2c data.gpr data.csv
Program received signal SIGSEGV, Segmentation fault.
0xb7e1021b in getc () from /lib/tls/i686/cmov/libc.so.6
2007-07-06_liang-heart-s5-800_0635_R1.jpg gpr2csv.py
2007-07-06_liang-heart-s5-800_0635_W1.jpg gpr2cvs.c
2007-07-06_liang-heart-s5-800_labeled.jpg gpr2cvs.c~
data.gpr liang-heart-s5-800_635.tif
g2c
liang@liang-dv1381tu:~/Documents/Experiments/Ana-with-GenePix/liang20070706/heart$ gdb g2c
GNU gdb 6.6-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) set args data.gpr data.csv
(gdb) r
Starting program: /home/liang/Documents/Experiments/Ana-with-GenePix/liang20070706/heart/g2c data.gpr data.csv
Program received signal SIGSEGV, Segmentation fault.
0xb7e1021b in getc () from /lib/tls/i686/cmov/libc.so.6