Thread: Having troubles inputing information, program shuts down automatically

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    2

    Having troubles inputing information, program shuts down automatically

    first I'd like to apologize, I have troubles learning if not everything is explained to me.

    else I am learning C and going through the tutorial, it was explaining the variables. Now I wasnt too shocked to find 4 errors in my work so I copy/pasted the example to see how it was done right.

    most of you know this example, the input/output one. enter a number it goes to a variable and it is printed on the screen.

    well, and I knew there was this code for it, hitting enter shuts the program down. even with the gletcher code it doesnt pause long enough to post the output. How do you input the number without shutting the program down first?


    Thank you for time and help, (i couldnt find it in FAQ)
    Sorry for being new at programming, I just recently finnished learning basic webscripting.

    Also I dont know if it matters much but for information sake, I am using the Dev-C++ program suggested in tutorial. Thanks

  2. #2
    Registered User
    Join Date
    Jan 2006
    Location
    Washington D.C.
    Posts
    25
    Assuming you use windows, you could put

    Code:
    system("pause");
    just before the return, but if not, then you could pause it yourself with something as such:

    Code:
    char c = getchar();

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    2
    ok thanks alot.

    it works perfectly, I am now able to continue
    Last edited by The_newbie; 01-14-2006 at 01:20 PM.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Code:
    int ch;
    
    while((ch=getchar())!='\n' && ch!=EOF);
    getchar();
    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM
  3. Replies: 6
    Last Post: 07-10-2002, 07:45 PM
  4. Replies: 1
    Last Post: 12-26-2001, 03:00 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM