Alex Rivera | Logout

How do you keep the console from closing after the program is done in C?

Asked 2009-12-08T01:33:12.057
12

Possible Duplicate:
What is the Best Practice for Combating the Console Closing Issue?

How do you keep the console from closing after the program is done in C? When I try to search for it I find lots of stuff about C++ and other languages, but nothing for C. Also, even for C++ there doesn't seem to be a definitive answer.

So could someone please let me know what the simplest way (doesn't need to be super elegant) way to keep the console open after a C program is done running?

Edit
Report

2 Answers

10

Console applications are meant to be run from the console. If you do that, after running you'll be left with your console window, and can easily view the output of your program.

You can use something like getchar() to force the application to wait for a key-press.

answered 2009-12-08T01:36:39.647
0

Let the console close.

If you prohibit, in the program, the console from closing, it will make automation with your program difficult, or it will make the format of the program's input strange.

Instead, fix whatever's running the program in the first place, to not close the terminal window in the first place. If this is MS Visual Studio, try F5 (Start without debugging). If you need debugging, place a breakmark at the program's end. Otherwise, open a command prompt/terminal and run the program there yourself.

answered 2009-12-08T01:37:25.743

Your Answer