Reading floating point numbers

Martin Weitzel martin at mwtech.UUCP
Mon Sep 24 22:16:39 AEST 1990


In article <1990Sep21.160343.18870 at eagle.lerc.nasa.gov> vvcns at 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 at mwtech.UUCP, voice: 49-(0)6151-6 56 83



More information about the Comp.lang.c mailing list