How to pause in C?

后端 未结 10 868
清歌不尽
清歌不尽 2020-12-05 18:11

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?

10条回答
  •  执笔经年
    2020-12-05 18:58

    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.

提交回复
热议问题