scanf double

Discussion in 'C Programming' started by amarapreet, Aug 7, 2008.

  1. amarapreet

    amarapreet Guest

    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
    amarapreet, Aug 7, 2008
    #1
    1. Advertising

  2. amarapreet

    amarapreet Guest

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

    amarapreet wrote:
    > 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
    amarapreet, Aug 8, 2008
    #2
    1. Advertising

  3. amarapreet

    fnegroni Guest

    On Aug 7, 11:56 pm, amarapreet <> wrote:
    > 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.
    fnegroni, Aug 8, 2008
    #3
  4. amarapreet <> writes:
    > 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.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Aug 8, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sydex
    Replies:
    12
    Views:
    6,473
    Victor Bazarov
    Feb 17, 2005
  2. Frank Chow

    Problem: scanf used for double

    Frank Chow, Oct 16, 2003, in forum: C Programming
    Replies:
    16
    Views:
    613
    Irrwahn Grausewitz
    Oct 17, 2003
  3. Red Dragon

    scanf to handle double

    Red Dragon, Nov 3, 2005, in forum: C Programming
    Replies:
    10
    Views:
    726
    Red Dragon
    Nov 3, 2005
  4. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc.

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Feb 16, 2006, in forum: C Programming
    Replies:
    185
    Views:
    3,386
    those who know me have no need of my name
    Apr 3, 2006
  5. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005?

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Apr 26, 2006, in forum: C Programming
    Replies:
    18
    Views:
    673
    Richard Bos
    May 2, 2006
Loading...

Share This Page