How can I fscanf for both float and double, as I declared a global precision once in single precision (float) and once in double precision (double)… so when I run it, I have to change it everytime that I convert to a different type
in double (%lf)
in single (%f)
fscanf(fp1,"%lf", &a[i][j]);
so is there’s a way that works for both and no need to change it every time?
Been a while since I did any coding in C, so you may want to confirm via experimentation, but all single-precision floats are valid double-precision floats, so you could just use ‘%lf’ in the fscanf, store to a temporary double-precision float, and then use logic to assign it to the correct variable.
Alternatively, if you’re using “#define”s, you could just do something like: