2 wanwanvsbenben wanwanvsbenben 于 2014.10.15 21:42 提问

Linux C 编程中segmentation fault (core dump)错误

Linux C 小白,求大神指导,不胜感激。原代码在Windows下用VC++6.0编写,能正常运行,后复制到Ubuntu 12.04下,改了一部分命令,编译能通过,但在运行时报错segmentation fault (core dump)。下面为代码:
#include
#include
#include
#include
#include
double num;

int WriteDat(){

FILE *Data;

    const char *path1="/home/wanwan/Ai.txt";

    Data=fopen(path1,"a+");

printf("%lf\n",num); 

fprintf(Data,"%lf\n",num);

fclose(Data);

    return 1;

}

int main( ) {

FILE *fin;

int data1,data2,data3,data4 ;

int n,i;

    const char *path2="/home/wanwan/hotness.txt";

    fin = fopen(path2,"r");

for (i=0;i<37;i++){

    fscanf(fin,"%d %d %d %d", &data1, &data2, &data3, &data4); 

    num=0.001*data1+0.3*data2+0.2*data3+0.5*data4;

    WriteDat();

        }
    fclose(fin); 

            return 0;

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!