【发布时间】:2020-12-15 19:24:57
【问题描述】:
我有以下代码:
#include "Analysis.h"
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string.h>
int main(){
FILE *TS;
//Input Files
TS = fopen("IceDat2C.dat","r");
//Parametrization
int i=0,j=0,k=0;;
double temp,tscale;
int points = 3606930
double T[points],A[points],sd[points];
int n[points];
fscanf(TS,"%d %lf %lf %lf\n",&n[j],&A[j],&T[j],&sd[j]);
return 1;
}
程序将返回段。故障:11 每次,除非 scanf 功能不存在。 这是 .dat 文件的样子:带零的列最终有实数。
1 0.075 1.79 0
2 0.075 1.84 0
3 0.075 1.89 0
4 0.075 1.84 0
5 0.075 1.73 0
6 0.075 1.61 0
7 0.075 1.49 0
8 0.075 1.35 0
9 0.075 1.22 0
10 0.075 1.07 0
11 0.075 0.98 0
12 0.075 0.98 0
13 0.075 0.97 0
14 0.075 0.97 0
15 0.075 0.96 0
16 0.075 0.94 0
17 0.075 0.93 0
18 0.075 0.91 0
19 0.075 0.89 0
20 0.075 0.86 0
我不确定我是否理解为什么这只是扫描失败。我使用相同的代码来扫描具有两列的文件,并且事情已经解决了。希望大家能帮帮我。
【问题讨论】:
-
将您的数组移动到文件/全局范围以绕过 dbush 提到的内容。把这个上面
main:#define POINTS 3606930后跟:double T[POINTS],A[POINTS],sd[POINTS];
标签: arrays c macos segmentation-fault scanf