C: Console window disappears.

Here is something I want to share with you.

If you program in C, with some console windows, the window might disappear after execution.

If you want to prevent that just add this line in front of the return 0; line in your main(void) 🙂

while(getchar() != '\n');

getchar() is defined in stdio.h.

What it basically does is wait for an end of line input (return key). Just press that and the window closes, end of the program!

Or you can try this (I read this in the comments, thanks!):


4 replies on “C: Console window disappears.”

  1. Goede methode 🙂 Maar waarom niet gewoon een scanf() toevoegen op het einde?
    Doet hetzelfde (maar dan bij elke toets).


  2. Hier de propere code die de system(“pause”); nabootst in c#

    public static void Pause()
    Console.Write(“Press any key to continue . . . “);



Comments are closed.