First scanf() skips next scanf() !

This is a discussion on First scanf() skips next scanf() ! within the C Programming forums, part of the General Programming Boards category; I have an input at the beginning of the program, which asks for a character, and a second input soon ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    1

    First scanf() skips next scanf() !

    I have an input at the beginning of the program, which asks for a character, and a second input soon after.

    When you input the character and press return, it runs through the rest of the program, skipping the next scanf(), not allowing the user to input.

    This problem occurs with either scanf() or getchar().
    Can anyone make a suggestion?

    -Graham

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Try reading this thread, and the links provided in it.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    you will probably have to flush the stream before the second scanf()

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    >>you will probably have to flush the stream before the second scanf()

    Probably not.

    gg

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    21
    fflush(stdin) before the second scanf because the scanf for the first one captures both the char and return key and treats them both as characters

  6. #6
    Goscinny or Uderzo?
    Join Date
    Jun 2004
    Posts
    33
    Quote Originally Posted by bennyho03
    fflush(stdin) before the second scanf because the scanf for the first one captures both the char and return key and treats them both as characters
    Bennyho03- don't use fflush(stdin). read this-
    http://faq.cprogramming.com/cgi-bin/...&id=1043284351

    With regard to the problem, the link so kindly provided by quzah should do the trick for you. If not then the problem could be elsewhere and seeing some code would help (just place the correct portion in [CODE] tags
    Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?

    (How much wood would a wood chuck cut if a wood chuck could chuck wood?)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf skips lines of code in DOS using Dev-C++ and Windows XP
    By jenovanomusuko in forum C Programming
    Replies: 9
    Last Post: 12-21-2008, 02:10 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. my program skips scanf and getchar()
    By jk81 in forum C Programming
    Replies: 15
    Last Post: 11-29-2002, 04:54 PM
  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