如果我有一个文件包含带有 float 的行,如下所示:
4.5 -3.2 3.3 5.62 0.56 3.231
5.632 -4.56 2 5.8212 4 6.7
如何逐行读取它并拆分数字以将它们保存在数组中(它们由 1 个制表符分隔)。
谢谢
编辑:
我做了以下操作,效果很好,感谢大家的帮助
#include <stdio.h>
#include <stdlib.h>
int main(){
float array[2][6];
FILE *f;
f=fopen("input.txt", "r");
int i = 0;
int j = 0;
for(i=0; i<2; i++){
for(j=0;j<6;j++){
fscanf(f,"%f",&array[i][j]);
}
}
for(i=0; i<2; i++){
for(j=0;j<6;j++){
printf("%f ", array[i][j]);
}
}
}
最佳答案
关于c - 在C中以不同精度从文件中读取 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35189029/