Sleep function in Windows, using C

RYN picture RYN · Jul 31, 2010 · Viewed 175.8k times · Source

I need to sleep my program in Windows. What header file has the sleep function?

Answer

anon picture anon · Jul 31, 2010

Use:

#include <windows.h>

Sleep(sometime_in_millisecs); // Note uppercase S

And here's a small example that compiles with MinGW and does what it says on the tin:

#include <windows.h>
#include <stdio.h>

int main() {
    printf( "starting to sleep...\n" );
    Sleep(3000); // Sleep three seconds
    printf("sleep ended\n");
}