DIGIT-ARC read-only archive · snapshot: July 23, 2026

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

10 posts · originally from https://geek.digit.in/community/threads/how-to-put-a-delay-in-execution-in-a-c-program.120933/

ionicsachin
ionicsachin Original post #1
Sep 11, 2009 at 12:38 AM
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?
L
Sep 11, 2009 at 1:20 AM
AFAIK there is no such standard function for putting delay
u have to be platform specific in this case
clmlbx
clmlbx #3
Sep 11, 2009 at 5:10 AM
#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
X
Sep 11, 2009 at 6:00 PM
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 at 8:25 PM
^^ +1
just include <dos.h>

and u can use this function "delay()" anywhere in any standard C program.
A
Sep 28, 2009 at 11:50 AM
Hai,
You can use delay(int n) defined in dos.h
vamsi360
Sep 28, 2009 at 5:01 PM
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
ruturaj3 #10
Sep 29, 2009 at 7:40 AM
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.