Help with Basic C Programing Closing

Discussion in 'C' started by AKalair, Nov 20, 2007.

  1. AKalair

    AKalair New Member

    Joined:
    Nov 20, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    Im learning C and currently going through the tutorials on Cprogramming.com. However when I compile there second 'example' I enter a number and it closes too quick to read the output. If I run it in debug mode on Bloodshed Dev c++ it stays open and I can read the output. Ive tried adding things like return 0; to the end but im new to this and it never made a difference can anyone help me get the window to stay open?

    Code:
    #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 );
      getchar();
    }
    
    The tutorial im using is here: Click Me

    Thank you in advance.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Just try putting the fflush function before the last getchar function.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice