Thread: I am trying to make a short Quizz for fun

  1. #16
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    No need to start all over again, that's a minor issue easily addressed. Notice I foresaw this happening and mentioned it in post #5. I recommend you check out the link in that post.

    Basically, you are typing 'y' and pressing enter.

    This puts two characters on the input buffer: 'y' and '\n' (the newline).

    The first "scanf()" reads the 'y' - but the newline is still waiting on the buffer.

    When the second "scanf()" is reached, it consumes that newline. This makes it appear as if it were skipped.

    A simple solution is to add a space to the format string; that is, change this:

    Code:
    scanf("%c", &response);
    ... to this:

    Code:
    scanf(" %c", &response);  // note the space before %
    This tells "scanf()" to consume all whitespace before trying to read the next character.

  2. #17
    Registered User
    Join Date
    Nov 2015
    Location
    Serbia, Dimitrovgrad
    Posts
    12
    Oh my god! I did read all of this, I opened the link that you've provided but I didn't really understand it that well. Ah I gotta focus more...
    Thanks for explaining it! It works, so happy right now~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I make this code short by for looping?
    By thisbeme in forum C Programming
    Replies: 8
    Last Post: 03-11-2011, 05:41 AM
  2. tutorial quizz question for switch operator
    By asem0525 in forum C Programming
    Replies: 7
    Last Post: 11-18-2006, 05:56 PM
  3. Replies: 19
    Last Post: 08-15-2005, 06:02 AM
  4. Nice quizz!
    By alfmep in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 04-27-2004, 04:50 AM