First, use System command pause
There is a pause command in the DOS command that pauses the current program and, according to the operating system language, gives
Please press any key to continue ...
or other language hints of the same meaning.
The program continues to run when any key input is detected
Header file:stdlib.h.
Function Purpose: Invoke system commands.
Function prototype: int system (const char *command);
Arguments: command is a string of commands to be executed.
Return value: The result of running the command.
by System ("pause"), the purpose of the suspension can be achieved.
Because the pause itself has output, there is no need to add additional prompts in the code.
#include <stdio.h>
#include <stdlib.h>
void Main ()
{
//function code to execute
system ("pause"); /wait for terminal to enter any character
}
second, using the Getch function
Header file:conio.h.
function Purpose: Reads a character from the console, but does not appear on the screen.
Function prototype: int getch (void);
Return value: the character read.
#include <stdio.h>
#include <conio.h>
void Main ()
{
//function code to execute
getch ();/ Wait for the terminal to enter any character
}
third, through the Exit Function
Header file:stdlib.h.
function Purpose: Force exit program.
Function prototype: void exit (int value);
Parameter: value, which is equivalent to the return value when exiting in main, is passed to the keynote process, that is, the process that invokes the executable program.
#include <stdio.h>
#include <stdlib.h>
void Main ()
{
//function code to execute
exit (0); Wait for the terminal to enter any character
}
four, by calling the return statement
#include <stdio.h>
int main ()
{
//function code to perform return
0;
}