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



## ionicsachin (Sep 11, 2009)

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?


----------



## lucifer_is_back (Sep 11, 2009)

AFAIK there is no such standard function for putting delay 
u have to be platform specific in this case


----------



## clmlbx (Sep 11, 2009)

#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 (Sep 11, 2009)

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.


----------



## pr.itdude (Sep 11, 2009)

^^ +1
just include <dos.h>

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


----------



## lucifer_is_back (Sep 13, 2009)

pr.itdude said:


> ^^ +1
> just include <dos.h>
> 
> and u can use this function "delay()" anywhere in *any standard C program*.


----------



## ashik.thomas (Sep 28, 2009)

Hai,
You can use delay(int n) defined in dos.h


----------



## vamsi360 (Sep 28, 2009)

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.


----------



## anuvrat_parashar (Sep 28, 2009)

pr.itdude said:


> ^^ +1
> just include <dos.h>
> 
> and u can use this function "delay()" anywhere in any standard C program.


I think this one will only work for Turbo C/C++ compiler.


----------



## ruturaj3 (Sep 29, 2009)

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.


----------

