I am a beginner of C. I run the C program, but the window closes too fast before I can see anything. How can I pause the window?
Under POSIX systems, the best solution seems to use:
#include
pause ();
If the process receives a signal whose effect is to terminate it (typically by typing Ctrl+C in the terminal), then pause
will not return and the process will effectively be terminated by this signal. A more advanced usage is to use a signal-catching function, called when the corresponding signal is received, after which pause
returns, resuming the process.
Note: using getchar()
will not work is the standard input is redirected; hence this more general solution.