Hi.
I study C. I need a function or something that will cause delay of given number of seconds, like delay(20) would wait 20 seconds before continuing.
How can I do that in C language?
Thank you.
4 replies to this topic
#1
Posted 21 July 2011 - 12:24 PM
I am a student of C language.
|
|
|
#2
Posted 21 July 2011 - 03:54 PM
What is your operating system and compiler? There is no simple way in plain C, however you may utilize an API to better this.
With C in Windows, you can always include windows.h and use the Sleep(milliseconds) function, in POSIX systems it will be unistd.h and sleep(seconds).
Sleep Function (Windows)
sleep (opengroup)
Alexander.
With C in Windows, you can always include windows.h and use the Sleep(milliseconds) function, in POSIX systems it will be unistd.h and sleep(seconds).
Sleep Function (Windows)
sleep (opengroup)
Alexander.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 23 July 2011 - 05:04 AM
If you are really on same platform which does not have a standard API, you can still do some experiment and based upon processor speed you can write code to do the job.
A little wild idea.
The above takes 3.2 - 3.4 seconds on my pc using codeblocks.
A little wild idea.
for(int i=0; i<1000000000; i++);
The above takes 3.2 - 3.4 seconds on my pc using codeblocks.
Today is the first day of the rest of my life
#4
Posted 23 July 2011 - 04:12 PM
Maybe I would do a while loop and compare time (assuming time.h is provided on that system) - however this would be harsh on the CPU for more than a moment.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









