views
Steps
Make your CPU work for some time without producing any noticeable event.
Do no other operation during that delay, in order to create a simple time-delay.
The "for-loop" technique
Use a typical "for" loop followed by a null statement to implement time delay.
Write as follows, for an example: for (i=1 ; i<100 ; i++) ; The statement followed by the ";" makes the computer execute the loop 100 times without any noticeable event. It just creates a time delay.
The "sleep()" Technique
Use sleep() The function called sleep(int ms) declared in
Include the following line in your program before "int main()":
#include
Insert, wherever you need your program to make a delay: sleep(1000); Change the "1000" to the number of milliseconds you want to wait (for example, if you want to make a 2 second delay, replace it with "2000". Tip: On some systems the value might refer to seconds, instead of milliseconds. So sometimes 1000 isn't one second, but, in fact, 1000 seconds.
Comments
0 comment