469,602 Members | 1,727 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

How to make code run every X seconds in C programming language

I am trying to make a code run repeatedly every X seconds.

Let me paint a wrestling scenario.

I have already written a code line to give Tyson fury a 5Kg punch at 40 seconds into the fight and then stop.. but there's no way I'm going to win the match with just one 5kg punch at 40 seconds. I need to be able to keep punching every 40 seconds.

Please who knows how I can achieve this?
Oct 20 '21 #1
1 4840
dev7060
519 Expert 512MB
I am trying to make a code run repeatedly every X seconds.

Let me paint a wrestling scenario.

I have already written a code line to give Tyson fury a 5Kg punch at 40 seconds into the fight and then stop.. but there's no way I'm going to win the match with just one 5kg punch at 40 seconds. I need to be able to keep punching every 40 seconds.
https://en.wikipedia.org/wiki/Sleep_(system_call)
Expand|Select|Wrap|Line Numbers
  1.     while(...){
  2.         //do something
  3.         sleep(time);
  4.     }
Oct 22 '21 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

33 posts views Thread by Joe Cheng | last post: by
134 posts views Thread by evolnet.regular | last post: by
25 posts views Thread by Dave | last post: by
7 posts views Thread by Robert Seacord | last post: by
43 posts views Thread by Adem24 | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.