Keeping Your Application Open

If your application ran so quickly that you didn't even have time to see it, don't be surprised. The reason for this is that on some operating systems (think Windows here) the console application will open, the C executable will run, and the console will close again—that is, unless you do something to stop it.

So here's a little trick you can use if you are having this problem. Simply open your hello.c script and add the getchar() function to your main() function. This will make the application wait for the Enter or Return key to be pressed before continuing to execute.

To keep your application open using getchar()

1.
Open hello.c (Script 1.2) in your text editor or IDE.
2.
After the printf() line and before return ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.