Development C: Probably a silly question but...

Discussion in 'Software' started by Evilbob, 21 Mar 2005.

  1. Evilbob

    Evilbob What's a Dremel?

    Joined:
    28 Apr 2001
    Posts:
    550
    Likes Received:
    0
    How do i use doubles? I use them with pre-defined values but when I try to get one from a scanf("%f",var); prompt and it doesnt seem to work? can anyone suggest what difference i need to use compared to a float variable?
     
  2. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    Err, from memory:

    Code:
    scanf("%lf",var)
    :)

    i should check these things before posting
     
  3. Hepath

    Hepath Minimodder

    Joined:
    20 Oct 2003
    Posts:
    730
    Likes Received:
    0
    pants! Ithought it was "%d" ;) (again fom memory - got it wrong ;))

    Size Prefixes for scanf and wscanf Format-Type Specifiers

    To specify Use prefix With type specifier
    double l e, E, f, g, or G
    long double (same as double) L e, E, f, g, or G
    long int l d, i, o, x, or X
    long unsigned int l u
    short int h d, i, o, x, or X
    short unsigned int h u
    __int64 I64 d, i, o, u, x, or X
    Single-byte character with scanf h c or C
    Single-byte character with wscanf h c or C
    Wide character with scanf l c or C
    Wide character with wscanf l c, or C
    Single-byte – character string with scanf h s or S
    Single-byte – character string with wscanf h s or S
    Wide-character string with scanf l s or S
    Wide-character string with wscanf l s or S
     
  4. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    if its a scanf issue then surely its because your passing a value, not a pointer.

    like so

    scanf("%f",&dVar);

    :D
     
  5. Henchman:crg

    Henchman:crg What's a Dremel?

    Joined:
    9 Feb 2005
    Posts:
    749
    Likes Received:
    0
    Good point, except use %lf (as described on MSDN) or described here: http://www.cplusplus.com/ref/cstdio/scanf.html
     
  6. Evilbob

    Evilbob What's a Dremel?

    Joined:
    28 Apr 2001
    Posts:
    550
    Likes Received:
    0
    sorry to confuse you all but i meant to put a % in front of the var name i did the %lf thing and it works ... no problems there. i later compiled my program with GCC and %lf gave me a warning because its not strictly ANSI C
     
  7. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    the nice thing about standards is there are soo many to choose from.

    C comes in many flavours, thats the horrible thing about it

    java/.net excite me, native CPU support can be very fast. JIT'ing is very fast too, but i'd like to see more people using languages that compile to a VM, then cross compile to a localised binary.
     
  8. Hepath

    Hepath Minimodder

    Joined:
    20 Oct 2003
    Posts:
    730
    Likes Received:
    0
    Animus if you get experience of using NGEN on different platforms I'd be interested to hear what you find.

    The company I'm currently working for refuse to allow it so I've not been able to try it in anger....
     
  9. Henchman:crg

    Henchman:crg What's a Dremel?

    Joined:
    9 Feb 2005
    Posts:
    749
    Likes Received:
    0
    I'm guessing you meant to put & in front of var name? :)
     
  10. Henchman:crg

    Henchman:crg What's a Dremel?

    Joined:
    9 Feb 2005
    Posts:
    749
    Likes Received:
    0
    Well, that depends on the what you are trying to do.
    You wouldn't want to create a graphics rendering engine running interpreted, especially for a web server with thousands of hits per day.

    Everything has it's time and place.
     

Share This Page