How to put a delay in execution in a C program?

Status
Not open for further replies.

ionicsachin

Ambassador of Buzz
Hiii,
I wanted to know how to put a delay of milliseconds or seconds at any step in a C program. On googling i came across sleep(), but its not a standard C funtion. Any suggestions?
 

clmlbx

Technomancer
#include "stdio.h"
#include "time.h"
int main(void){
struct timespec t;
t.tv_sec = 0;
t.tv_nsec = 500000000;
while(1){
printf("Hello world!\n");
nanosleep(&t,NULL);
}
return 0;
}


NOT THAT GOOD IN C .. This I have copied from somewhere else
 

xmentrio

Broken In
There is also delay(int msec) function in dos.h.
Try using it. It works.
-----------------------------------------
Posted again:
-----------------------------------------
There is also delay(int msec) function in dos.h.
Try using it. It works.
 
Last edited:

pr.itdude

tHe nEw gEEk......ITian
^^ +1
just include <dos.h>

and u can use this function "delay()" anywhere in any standard C program.
 

vamsi360

Always confused
are you looking in Debugginh case?

using Visual C++ you have more ease with debugging. Or use Geany and Mingw in Windows or Geany and gcc in Linux.
 

ruturaj3

Journeyman
yes, delay() function works well, u can used it in drawing animation or displaying msg, like calculating result and then after delay display d result.
Instead of directly printing output.
 
Status
Not open for further replies.
Top Bottom