In C, I want a block of statements to be executed repeatedly every t seconds. How do I do this?
This cannot be done in standard C, you need to use some platform-specific API.
One popular choice is POSIX' alarm()
function.
This is a "pure" aynchronuous solution. It's of course possible to measure and handle time in other ways, but they're still platform-dependent. You could use sleep()
(again, POSIX) to just block. If you combine that with your desired statements in a loop, that should work too.
You will need to create a thread or process that runs a loop containing a wait request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With