Using SCANF with DOUBLE precision variables...

Andrew Koenig ark at alice.UucP
Thu Sep 11 06:13:19 AEST 1986


> 'Ello,
>       I've been doing a little matrix algebra in C lately, and in the process
> I have been wanting to read in some real numbers, preferably thru SCANF, but I
> get nothing but 0.000 returned when i try to put the result of a SCANF in a var
> declared as DOUBLE.  The only thing that I could think of was either writing my
> own algorithm, or reading the number in as FLOAT and storing it in the DOUBLE
> variable.  Perchance someone else has had this problem and found a better
> solution without re-inventing several wheels?  I guess there really isn't any
> reason why I just couldn't use FLOAT variables, but then there shouldn't be any
> reason why I can't use SCANF on DOUBLE vars either.
>      Thanks in advance,
>                        Dave

	float f;
	double d;

	scanf ("%f", &f);		/* should work */
	scanf ("%f", &d);		/* garbage */
	scanf ("%lf", &d);		/* should work */
	scanf ("%lf", &f);		/* garbage */



More information about the Comp.lang.c mailing list