Thread: Using scanf() ??

  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,210
    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,210
    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, 08:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 04:39 PM
  3. Replies: 2
    Last Post: 02-20-2005, 01: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