How to Delay in C
Method 1 of 2:
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
- The statement followed by the ";" makes the computer execute the loop 100 times without any noticeable event. It just creates a time delay.
Method 2 of 2:
The "sleep()" Technique
- Use sleep() The function called sleep(int ms) declared in which makes the program wait for the time in milliseconds specified.
- 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.
5 ★ | 1 Vote
You should read it
- Simulation of Titan submersible explosion takes place in less than 14 milliseconds
- 15 'truths' completely wrong about sleep (part 1)
- How to Adjust Subtitle and Voice Delay on VLC Player
- 5 things you may not know about sleep
- 6 best sleep monitoring and application apps on iOS
- How to disable Startup Delay in Windows 10
- How to delay starting OneDrive on Windows 10/8/7
- How to sleep in less than 1 minute?
May be interested
- How to Set Up SDL with Visual Studiowhether you're a novice c++ programmer or a veteran software developer, graphics programming is an educational and rewarding experience. simple directmedia layer is a c library (compatible with c++) that allows simple, low-level access, to...
- How to Write Standard Code in C++there are infinitely many ways to program computers. ultimately, it is the choice of the programmer how to accomplish what they need. there are, however, many 'best practices' for styles and function usage for better compilation and safer...
- How to Get Color in C Programchanging the color of text or shapes in your c program can help them pop when the user runs your program. changing the color of your text and objects is a fairly straightforward process, and the necessary functions are included in the...
- How to Learn to Program in Cc is one of the older programming languages. it was developed in the 70s, but it is still very powerful thanks to how low-level it is. learning c is a great way to introduce yourself to more complex languages as well, and the knowledge you...
- How to Compile a C Program Using the GNU Compiler (GCC)this wikihow teaches you how to compile a c program from source code by using the gnu compiler (gcc) for linux and minimalist gnu (mingw) for windows. open up a terminal window on your unix system. its icon usually is a black screen with...
- Memmove function in Cvoid function * memmove (void * str1, const void * str2, size_t n) copy n characters from str2 to str1, but to solve the matching of memory blocks, memmove () is a safe approach more than memcpy ().