Fantastic Fourier
Fantastic Fourier

Reputation: 613

looking for a function that doesn't do anything/ waits

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

Answers (4)

caf
caf

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

gfe
gfe

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

Ants
Ants

Reputation: 2668

I believe you are looking for the sleep() or usleep() functions.

Upvotes: 3

shinkou
shinkou

Reputation: 5154

Take a look at this if you're on *nix.

Upvotes: 1

Related Questions