Reputation: 613
for C, is there a function that takes an int and doesn't execute next statement ?
printf("a");
wait(500);
printf("b");
b will be printed after 500ms after a is printed out. something of the sort. sorry for the stupid question but i wasn't sure how to go about searching for such function.
Upvotes: 1
Views: 158
Reputation: 239011
There is nothing like that in standard C. However, POSIX defines the sleep()
function (which takes an argument in seconds), usleep()
(which takes an argument in microseconds), and nanosleep()
(nanosecond resolution).
It is also possible to use the select()
function with NULL
for all three file descriptor sets to sleep for sub-second periods, on older systems which don't have usleep()
or nanosleep()
(this is not so much a concern these days).
Upvotes: 9
Reputation: 774
On Windows you could try:
#include <windows.h>
int main()
{
// Do nothing for 5 seconds...
Sleep(5000);
return 0;
}
Read more about this, here (official doc) or here (linux too).
Upvotes: 3