Article View: net.lang.c
Article #9287Re: Using SCANF with DOUBLE precision variables...
From: Andrew Koenig
Date: Wed, 10 Sep 1986 20:13
Date: Wed, 10 Sep 1986 20:13
20 lines
1454 bytes
1454 bytes
> '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 */
Technical Details
Message-ID:
<6043@alice.uUCp>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!columbia!caip!princeton!allegra!alice!arkReferences:
<3672@brl-smoke.ARPA>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!columbia!caip!princeton!allegra!alice!ark From: ark@alice.UucP (Andrew Koenig) Newsgroups: net.lang.c Subject: Re: Using SCANF with DOUBLE precision variables... Message-ID: <6043@alice.uUCp> Date: Wed, 10-Sep-86 16:13:19 EDT Article-I.D.: alice.6043 Posted: Wed Sep 10 16:13:19 1986 Date-Received: Thu, 11-Sep-86 02:04:40 EDT References: <3672@brl-smoke.ARPA> Organization: Bell Labs, Murray Hill Lines: 20