vvcns@mars.lerc.nasa.gov (Allen Holtz) (09/21/90)
I am trying to read floating point numbers from a file using the following: fscanf(pointer,"%f",&arg); The correct data is not being read. Instead, totally random numbers are read in. Is there a certain way to read floating point numbers from a file. All suggestions are welcome. Thanks in advance, Allen -------------------------------------------------------------------------------- Allen Holtz -------------------------------------------------------------------------------- Imagination is more important than knowledge. - Albert Einstein --------------------------------------------------------------------------------
martin@mwtech.UUCP (Martin Weitzel) (09/24/90)
In article <1990Sep21.160343.18870@eagle.lerc.nasa.gov> vvcns@mars.lerc.nasa.gov writes:
[tries to read floating point numbers with fscanf(pointer,"%f",&arg);
but gets only random numbers]
May I suppose "arg" isn't declared as float, but as double?
In this case "%lf" were the proper format specifier.
(Because float-s are propagated to double-s if used as argument
*values*, this problem doesn't appear in printf and hence is often
overlooked with scanf.)
Another possible source of problems are the "locales" (new in ANSI-C).
The character which separates the decimal part may depend on the current
locale and hence he locale should be the same for writing and reading
floats.
--
Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83