scanf double

A

amarapreet

hi gcc 3.4 says in a warning that %lf is not recognized as a scanf
format specifier is this right if so how to read in a double using scanf
thanks
 
A

amarapreet

hi sorry this is c90 options recommended in this forum -W -Wall -ansi
-pedantic thanks
 
F

fnegroni

hi gcc 3.4 says in a warning that %lf is not recognized as a scanf
format specifier is this right if so how to read in a double using scanf
thanks

Can you post an equivalent program that exhibits that compile time
diagnostic to be generated?
Could you also post the command line you use to invoke the compiler?
Thanks.
 
K

Keith Thompson

amarapreet said:
hi gcc 3.4 says in a warning that %lf is not recognized as a scanf
format specifier is this right if so how to read in a double using
scanf thanks

"%lf" is the correct format specifier to read a double using scanf in
both C90 and C99.

You haven't shown us either your code or the warning. If you had
posted the exact code that you fed to the compiler (copy-and-paste a
complete program; don't try to re-type it) *and* the exact diagnostics
the compiler gave you, then we could probably tell you what the
problem is. Given the lack of information you've shared with us,
though, we can only guess.

Here's my guess. You wrote something like this:

double d;
scanf("%lf", d);

and the warning was something like this:

c.c:5: warning: format '%lf' expects type 'double *', but argument 2 has type 'double'

scanf needs the address of the object you're reading, not the value of
the object:

double d;
scanf("%lf", &d);

Don't blame me if I've guessed wrong. Show us the code and the
warning.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top