它看起来很常见而且显而易见但我已经在过去读过C中的txt文件,而且我真的被卡住了.
我有这种格式的txt文件
0.00000587898458 0.0014451541000 0.000000000001245
0.00012454712235 0.1245465756945 0.012454712115140
Run Code Online (Sandbox Code Playgroud)
...有640列和480行.
我想将我的txt文件的每个数字放在一个浮点数中,尽可能保持最大精度,并在for循环中.
FILE* myfile=NULL;
double myvariable=0.0;
myfile=fopen("myfile.txt","r");
for(i =0, k=0 ; i< height; i++)
for (j=0 ; j< width ; j++){
fscanf(myfile,"%0.20f",&myvariable);
printf("%0.20f",myvariable);
k++;
}
}
fclose(myfile);
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助