C/C++ How can I add a time delay before the exit command in C/C++?

  • Thread starter Thread starter Akshay_Anti
  • Start date Start date
  • Tags Tags
    Delay
AI Thread Summary
To delay the execution of the exit(0) command in a program, a sleep function can be utilized to pause the program for a specified duration before exiting. This allows for a message to be displayed to the user prior to termination. Additionally, incorporating a prompt for user input, such as asking the user to press the enter key, can also serve as a method to create a pause before the program exits. This approach ensures that users have time to read any final messages before the program closes.
Akshay_Anti
Messages
62
Reaction score
0
Hello! I was writing a basic program and was wondering about this problem:-

when i give exit(0); the compiler exits as soon as that part of code is reached. Is there any piece of code such that after it reaches that part of code, it waits for some time before executing exit command? This can be used in case when upon exit, a message is to be displayed.

Thank you in advance
 
Technology news on Phys.org
thanks! :)
 
In your program you could include code just before the exit(0) to display a message to indicate the user should press the enter key, then wait for user input.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top