程序调试出现:It stopped with signal SIGSEV, Segmentation fault
我用c语言在c-free上写了一断小程序,结果运行时总是跳出对话框:
Debug Signal
Program stopped at 0x7c938fea.
It stopped with signal SIGSEGV,Segmentation fault
以前也写过类似的程序,都没有出现这种问题。
请高手指点一下为什么这样,如何解决。谢谢。
以下是程序源代码:
#include<stdio.h>
#include<math.h>
#include<malloc.h>
void main()
{ FILE *in1,*in2,*out;
char outfile[50];
double p[1620],ic[1620],f[1620];
double v;
int i;
if((in1=fopen("p.txt","r"))==NULL)
{ printf("cannot open spe infile name\n");
exit(0);
}
if((in2=fopen("ic-norm.txt","r"))==NULL)
{ printf("cannot open the ic infile name\n");
exit(0);
}
printf("enter the outfile name:\n");
scanf("%s",outfile);
if((out=fopen(outfile,"w"))==NULL)
{ printf("cannot open the outfile name\n");
exit(0);
}
for(i=0;i<1620;i++,in1++)
{ fscanf(in1,"%lf",&v);
p[i]=v;
}
for(i=0;i<1620;i++,in2++)
{ fscanf(in2,"%lf",&v);
ic[i]=v;
}
for(i=0;i<1620;i++)
f[i]=p[i]/ic[i];
for(i=0;i<1620;i++)
fprintf(out,"%f\n",f[i]);
fclose(in1);
fclose(in2);
fclose(out);
}
[解决办法]
char outfile[50];
double p[1620],ic[1620],f[1620];
函数堆栈溢出??
把char outfile[50];
double p[1620],ic[1620],f[1620];改成malloc试试看?
[解决办法]
据我所知除0会产生此信号,仔细检查一下你读入的文件是不是有0