LasTSurvivoR
- 16
- 0
I wrote my code and try to setup the program , desperately the program closes it so quickly return 0 or getch() commands doesn't work how can I prevent it with a code ?
The discussion revolves around methods to prevent a console program from closing immediately after execution in a Windows environment. Participants explore various coding techniques and command-line approaches to keep the console window open for user interaction.
getch(), getchar(), or system("pause") to pause the program and wait for user input before closing.Participants generally agree on the need for a solution to keep the console window open, but there are multiple proposed methods and some uncertainty about the effectiveness of each approach.
Some methods may depend on specific compiler settings or environments, and there is no consensus on the best approach among the participants.
Programmers working in C/C++ on Windows who encounter issues with console applications closing immediately after execution.
printf("\npress q to quit\n");
do
{
key = getchar();
} while (key != 'q');
printf("\npress q to quit\n");
do
{
key = getch();
} while (key != 'q');