I need to loop for a certain amount of time based on user input ( in C Program ).
Example: User says loop for 2 Minutes ( = 120 seconds).
while(time <= 2 Minutes)
{
do something
}
How would I go about doing this in C? Thanks for your help!!
I need to loop for a certain amount of time based on user input ( in C Program ).
Example: User says loop for 2 Minutes ( = 120 seconds).
while(time <= 2 Minutes)
{
do something
}
How would I go about doing this in C? Thanks for your help!!
You do not need to loop.
Just take a nap. It will sleep for the amount of time and let the processor to do something more useful
If you need to perform some operation as many times as possible within the specific period of time you can use time()
:
time_t secs = 120; // 2 minutes (can be retrieved from user's input)
time_t startTime = time(NULL);
while (time(NULL) - startTime < secs)
{
...
}