Thread: Stop/pause program after asking for input

  1. #1
    Registered User mrppinzon's Avatar
    Join Date
    Oct 2012

    Stop/pause program after asking for input

    Hello, I just started learning C using the guide on this page and I found a little problem I haven't been able to fix by myself.

    On some examples used on the guide, the program ask for an input and should give you a printf in return. However, after you enter the input, it will finish the program without giving you time to see the answer. What do I use to make it stop/pause in order to be able to read the answer?

    An example of this is:

    #include <stdio.h>
    int main()
        int this_is_a_number;
        printf( "Please enter a number: " );
        scanf( "%d", &this_is_a_number );
        printf( "You entered %d", this_is_a_number );
        return 0;

  2. #2
    Registered User
    Join Date
    Jun 2011
    If you enter, say, 4,then press 'enter', the input buffer contains:

    The newline remains in the buffer, and is devoured by your "getchar()", leading it to seem like it was skipped.
    To verify this, put a second "getchar()" after the first one and see if the window remains open.

    FAQ > Stop my Windows Console from disappearing everytime I run my program? -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I get input to stop at 'Esc' instead of \n ?
    By xkronix in forum C Programming
    Replies: 11
    Last Post: 09-17-2012, 11:07 AM
  2. Curses keyboard input without pause
    By guesst in forum Linux Programming
    Replies: 3
    Last Post: 04-14-2008, 10:22 AM
  3. stop input being echoed
    By Kinasz in forum C Programming
    Replies: 11
    Last Post: 07-25-2004, 11:02 AM
  4. input without pause
    By asafze in forum C Programming
    Replies: 3
    Last Post: 06-02-2004, 06:36 AM
  5. Pause in OpenGL, but don't stop drawing... ?
    By Arker in forum Game Programming
    Replies: 4
    Last Post: 10-16-2003, 10:34 PM
Website Security Test