www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/01/08/10:00:06

Date: Fri, 8 Jan 93 08:57:56 CST
From: "Jeremy Mathers" <pynq AT midway DOT uchicago DOT edu>
To: alane AT wozzle DOT linet DOT org
Subject: Re: scanf woes
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu

(In cases like this, it is hard to tell what he meant...)

>Richard Shields <src4src!mcdhup!rutgers!sequent.com!richards> writes:

>> 
>> Has anyone had any trouble using scanf to read in a floating point value?
>> 
>> I tried this in my code:
>> 
>>     double amount;
>> 
>>     scanf("%f", amount);
>>     printf("amount = %10.2f\n", amount);
>> 
>> 
>> When I run the program and enter 4.25 the printf statement prints 0.00.
>> 

>You told scanf to read in a "float", not a "double". Need to say "%lf".

Maybe he meant to declare amount as float.

Also, the program would probably work if he put a star after the comma
in the printf() call.  (Kids, don't try this at home...)

Please - no flames.  Dollar bills gratefully accepted, however.

Send to: Box 166011, Chicago, IL., 60616-6011

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019