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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top