Using scanf() ??

This is a discussion on Using scanf() ?? within the C Programming forums, part of the General Programming Boards category; When using scanf() to assign to a to a double is this the right way to do it: Code: scanf("%f%*c", ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    42

    Using scanf() ??

    When using scanf() to assign to a to a double is this the right way to do it:

    Code:
    scanf("%f%*c", double)
    
    or 
    
    scanf("%lf%*c", double)
    Thanks!

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Am I missing something? Why not do this?

    Code:
    double x;
    ...
    scanf("%lf",&x);
    ...

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    42
    Quote Originally Posted by leopardforest@g View Post
    When using scanf() to assign to a to a double is this the right way to do it:

    Code:
    scanf("%f%*c", double)
    
    or 
    
    scanf("%lf%*c", double)
    Thanks!
    ok am I just dumb or does it not matter? Doesn't it just depend on the type used ie: float, double, int ??

    Thanks!

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    42
    Quote Originally Posted by MacGyver View Post
    Am I missing something? Why not do this?

    Code:
    double x;
    ...
    scanf("%lf",&x);
    ...
    I just thought I remember someone telling me that scanf() only used %f . But maybe my memory is just failing me. Thank you!

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    I think to be technically correct, %f is for floats and %lf is for doubles.

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    42
    ok thank you very much that is what I thought. Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf() consideres useless
    By Snafuist in forum C Programming
    Replies: 15
    Last Post: 02-18-2009, 07:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 03:39 PM
  3. Replies: 2
    Last Post: 02-20-2005, 12:48 PM
  4. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 06:36 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 04:34 AM

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