Knemon
8/29/2006 11:13:00 PM
Mr John FO Evans wrote:
> The following code snippet fails on my system
>
> double dd;
> FILE * inf;
> inf=fopen(<filename>,"r");
> fscanf(inf,"%g",&dd);
>
> The text file opened is as follows:-
>
> 123.6
> etc
>
> The file opens correctly but the value of dd returned is nonsense!!
The correct specifier for a double in the fscanf specification string is
%lg, not %g.
This time you lucked out. Your uncompilable snippet with no main, no
#include <stdio.h>, and the illegal (and undeclared and uninitialized)
<filename> identifier could easily have been worthless to anyone trying
to help you. The fact that you accidentally included at least one of
your errors was just dumb luck. You had no idea what was wrong, so
failing to post a minimal compilable program showing the problem
behavior is just trying not to get a coherent answer.