fscanf函数读取多行多列数据文件
现在有这样一个数据文件,想用fscanf函数读取,每列作为一个数组,我自己写了个代码,运行错误,希望高手们帮我看看吧,多谢了!
1.000000e+000 2.000000e+000 -3.000000e+000
2.000000e+000 3.000000e+000 -2.000000e+000
3.000000e+000 4.000000e+000 -1.000000e+000
4.000000e+000 5.000000e+000 0.000000e+000
5.000000e+000 6.000000e+000 1.000000e+000
6.000000e+000 7.000000e+000 2.000000e+000
7.000000e+000 8.000000e+000 3.000000e+000
8.000000e+000 9.000000e+000 4.000000e+000
9.000000e+000 1.000000e+001 5.000000e+000
1.000000e+001 1.100000e+001 6.000000e+000
我写的代码如下:
# include <iostream>
int main(void){
FILE *fq;
double x[10], y[10], z[10];
fq=fopen("step.dat" ,"r+");
for (int i=1; i<=10; i++){
fscanf(fq,"%e %e %e\n",x[i], y[i], z[i]);
}
fclose(fq);
return 0;
}
1.000000e+000 2.000000e+000 -3.000000e+000
2.000000e+000 3.000000e+000 -2.000000e+000
3.000000e+000 4.000000e+000 -1.000000e+000
4.000000e+000 5.000000e+000 0.000000e+000
5.000000e+000 6.000000e+000 1.000000e+000
6.000000e+000 7.000000e+000 2.000000e+000
7.000000e+000 8.000000e+000 3.000000e+000
8.000000e+000 9.000000e+000 4.000000e+000
9.000000e+000 1.000000e+001 5.000000e+000
1.000000e+001 1.100000e+001 6.000000e+000
我写的代码如下:
# include <iostream>
int main(void){
FILE *fq;
double x[10], y[10], z[10];
fq=fopen("step.dat" ,"r+");
for (int i=1; i<=10; i++){
fscanf(fq,"%e %e %e\n",x[i], y[i], z[i]);
}
fclose(fq);
return 0;
}
...全文
相关推荐
fscanf类函数
fscanf()函数(有点像正则表达式): 功 能: 从一个流中执行格式化输入,fscanf遇到空格和换行时结束,注意空格时也结束。
matlab中的fscanf的用法
介绍matlab中的fscanf的用法,一目了然fscanf的语法格式
C语言中的fscanf()函数与vfscanf()函数使用
主要介绍了C语言中的fscanf()函数与vfscanf()函数使用,是C语言入门学习中的基础知识,需要的朋友可以参考下
fprintf()和fscanf()函数
printf()和fscanf()函数
从txt中读入数据到数组中(fscanf)的实现代码
C-sources: #include int main() { FILE* fp; //定义一个文件 fp = fopen(p5.txt,r); if(fp == NULL) { printf(ERROR!\N); return; } int TwoPointSignal[1000]; int n,k=0,j; while(!feof(fp)) { fscanf(fp,%d,&n); TwoPointSignal[k]=n; k++; } fclose(fp); for(j=0;


