sleep ms c code example
Example 1: c fractional sleep
#define _DEFAULT_SOURCE
#include "newSleep.h"
void fracSleep(float sec) {
struct timespec ts;
ts.tv_sec = (int) sec;
ts.tv_nsec = (sec - ((int) sec)) * 1000000000;
nanosleep(&ts,NULL);
}
fracSleep(0.5); //Half second delay
Example 2: use sleep in c in windows
#include <Windows.h>
int main()
{
Sleep(500);
}
Example 3: sleep in c
sleep(5); //sleep for 5 secs