stop scanf consming whitespace

This is a discussion on stop scanf consming whitespace within the C Programming forums, part of the General Programming Boards category; hi, im doing an assignment and im only allowed to use scanf, otherwise i would use fgets etc is there ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    2

    stop scanf consming whitespace

    hi,

    im doing an assignment and im only allowed to use scanf, otherwise i would use fgets etc

    is there a way i can stop scanf from consuming whitespace?

    thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Depends on what format you're using. Any numeric format (%d, %f) will consume whitespace while looking for a number, no matter what. %s will skip whitespace at the start. %c won't.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    2
    fair enough, their in %d.

    hmmm maybe if i use %c and convert back to numbers

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. Replies: 2
    Last Post: 02-20-2005, 01:48 PM
  3. scanf issue
    By fkheng in forum C Programming
    Replies: 6
    Last Post: 06-20-2003, 08:28 AM
  4. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 05:34 AM
  5. Whitespace and scanf()
    By Procyon in forum C Programming
    Replies: 1
    Last Post: 01-05-2002, 01:55 AM

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