I am trying to use fscanf
to read matrix data in a text file and do some matrix*vector calculation in C.
However I noticed that fscanf
read very small number such as -2.22E-10 to zero. Here is the code for reading the matrix from "D1_1.txt" file.
file = fopen("D1_1.txt", "r");
for (j = 0; j < matcols; j++) {
for (i = 0; i < matrows; i++) {
if (!fscanf(file, "%lf", &(data->D1_1data)[j + i*matcols]));
}
}
fclose(file);
And here is the screenshot image of the original data
And below, screenshot of the data read by fscanf (I use fprintf to write another txt file from C code)
As you can see, large number can be correctly read by fscanf
but not very small number such as 5.92e-10.
Is %lf not a good choice here ? What should I use to read all the numbers correctly ?
Thanks,