Better way to display lf numbers?

This is a discussion on Better way to display lf numbers? within the C Programming forums, part of the General Programming Boards category; hey, i'm getting a compiler error in Dev-C++ with a program for class. it says: Million_Fun.c:43: warning: ISO C90 does ...

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    Better way to display lf numbers?

    hey, i'm getting a compiler error in Dev-C++ with a program for class. it says:
    Million_Fun.c:43: warning: ISO C90 does not support the `%lf' printf format

    the line its referring to is:
    Code:
    printf("\n\n\n%d Years are required to reach $%.2lf\n", Years, Amount);
    so i was wondering if there was a better way to accomplish this? or is my format incorrect? thanks
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    what is lf?
    if amount is a double just use %f

    http://www.acm.uiuc.edu/webmonkeys/b...12.html#printf

  3. #3
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    lf is long float. my teacher said that a double was considered a long float when displaying it in this instance? or something like that..
    Registered Linux User #380033. Be counted: http://counter.li.org

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by willc0de4food
    warning: ISO C90 does not support the `%lf' printf format

    the line its referring to is:
    Code:
    printf("\n\n\n%d Years are required to reach $%.2lf\n", Years, Amount);
    so i was wondering if there was a better way to accomplish this? or is my format incorrect? thanks
    As the warning states, the format is incorrect for C90. And as already suggested, the C90 cure is to use %f -- this is different from scanf because printf is not scanf. Floating point arguments to printf are automatically promoted to double, and %f is the specifier for a double (and a float).

    It was a common extension to allow %lf for a double, even though it was non-standard code. C99 now allows this (by ignoring it).

    When it comes to scanf, we know* we pass a pointer, and this makes all the difference. Thus scanf has different specifiers for float and double.
    Quote Originally Posted by willc0de4food
    lf is long float. my teacher said that a double was considered a long float when displaying it in this instance? or something like that..
    What the compiler told you was correct. What sand_man told you was correct. What you say your teacher said, or what you believe you heard, appears suspect.


    *Hopefully.


    [edit]The relevant text from C90 is as follows:
    an optional l (ell) specifying that a following d , i , o , u , x , or X conversion specifier applies to a long int or unsigned long int argument; an optional l specifying that a following n conversion specifier applies to a pointer to a long int argument; or an optional L specifying that a following e , E , f , g , or G conversion specifier applies to a long double argument. If an h , l , or L appears with any other conversion specifier, the behavior is undefined.
    Last edited by Dave_Sinkula; 03-08-2005 at 10:39 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,442
    IIRC, the "long float" == "double" idea was removed in C89. So you should just be saying either "float" or "double" in your code, and use printf/scanf appropriately.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    alrighty. thanks guys
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Generate Random Numbers and Assign to Days of Week
    By mms in forum C++ Programming
    Replies: 10
    Last Post: 05-04-2006, 01:51 AM
  3. Array's Help
    By bmx4christ in forum C Programming
    Replies: 15
    Last Post: 12-08-2003, 11:40 AM
  4. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 09:54 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 05:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21