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

Via: uk.ac.aston; Fri, 8 Jan 1993 15:18:04 +0000
To: djgpp AT sun DOT soe DOT clarkson DOT edu
From: John Fletcher <ECM9093 AT pcmail DOT aston DOT ac DOT uk>
Date: 8 Jan 93 15:17:37 GMT
Subject: Re: scanf woes
Reply-To: J DOT P DOT Fletcher AT aston DOT ac DOT uk

> (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);

In the reference manual, amount should be &amount, i.e. the address
of the variable.

> >>     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...)
>

I hope this helps

John

---------------------------------------------------------------------
Dr John P. Fletcher
Department of Chemical Engineering and Applied Chemistry,
Aston University,         Tel: (44) 21 359 3611 ext 4625
Aston Triangle,         Email(Most systems): J DOT P DOT FLETCHER AT ASTON DOT AC DOT UK
BIRMINGHAM B4 7ET  U.K.   Email(JANET only): J DOT P DOT FLETCHER AT UK DOT ASTON DOT AC
---------------------------------------------------------------------

- Raw text -


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