Time in c | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Time in c

I want write program that run some function after every 200 millisecond , i already search for it and read some codes but those makes me so confused, is there simple way to do it ?

4th Mar 2019, 4:21 PM
AliR૯za
AliR૯za - avatar
8 Answers
+ 6
Fermi Perfect Thank you
5th Mar 2019, 9:51 AM
AliR૯za
AliR૯za - avatar
+ 6
Fidelis Search those questions in Q&A and if you don't find the answer that you want then ask it in Q&A
6th Mar 2019, 7:55 PM
AliR૯za
AliR૯za - avatar
+ 5
Aaron Eberhardt Right , Thank you
5th Mar 2019, 7:15 AM
AliR૯za
AliR૯za - avatar
+ 4
Ragan Murali Pasupuleti Thanks but sleep() stop and delay other statements and i don't want it happens I want use time.h library
4th Mar 2019, 7:03 PM
AliR૯za
AliR૯za - avatar
+ 4
// just replace the corresponding headers and functions with their C counterpart. #include <iostream> #include <ctime> int main() { std::clock_t t = clock(); unsigned long long i = 0; // wrapping up everything in a loop for (;;) { if (clock() - t > 1000) { // executes approx every 1 second (1000ms) std::cout << i << std::endl; t = clock(); } //remaining functionalities unaffected i++; // the rest of your code in here. // when your code execution is complete, break } return 0; }
5th Mar 2019, 7:27 AM
Fermi
Fermi - avatar
+ 3
sleep() function from stdlib.h
4th Mar 2019, 6:30 PM
Ragan Murali Pasupuleti
Ragan Murali Pasupuleti - avatar
+ 1
Here's a quite understandable explanation: http://www.cplusplus.com/reference/ctime/clock/
5th Mar 2019, 6:23 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 1
You can basically copy most parts of the example program. But instead I'd calculate how many ticks the clock needs for 200ms before with the CLOCKS_PER_SEC constant. Then check in a loop whether the clock has reached the amount of ticks you want.
5th Mar 2019, 6:27 AM
Aaron Eberhardt
Aaron Eberhardt - avatar