Thread: stop scanf consming whitespace

  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,336
    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, 07: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, 04:34 AM
  5. Whitespace and scanf()
    By Procyon in forum C Programming
    Replies: 1
    Last Post: 01-05-2002, 01:55 AM