【发布时间】:2019-05-02 13:09:03
【问题描述】:
我有一个这样的 257 点的文本文件
3.78135
2.84681
2.81403
2.54225
3.10854
...
我想读取这些数据并将它们复制到一个数组中。在类似的回答问题的帮助下,我写了这个:
#include<stdio.h>
#include<stdlib.h>
int max_read = 258;
double phi[max_read];
FILE *stream;
stream = fopen("namefile.txt", "r");
if (stream == NULL) {
print ("! Cannot open file %sn", "namefile.txt\n");
exit(1);
} else{
int m = 0;
while(m<max_read) {
phi[m] = // But I still don't know how write the correct value into the array.
m++;
}
}
我也想做这个阅读应对程序直到文件结束。
【问题讨论】:
-
你知道
scanf吗?你知道有一个fscanf可以从FILE *读取吗? -
不,抱歉,我不知道 :)