Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 11-09-2009, 12:38 AM   #1 (permalink)
Alpha Geek
 
ionicsachin's Avatar
 
Join Date: Apr 2005
Location: Hyderabad
Posts: 613
Default How to put a delay in execution in a C program?


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?
__________________
My first song
http://rapidshare.com/files/128849730/Sachin_-_In_My_Dreams.mp3
http://cid-e2d4f861e716a7fe.skydrive.live.com/self.aspx/.Public/Sachin%20-%20In%20My%20Dreams.mp3
ionicsachin is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 11-09-2009, 01:20 AM   #2 (permalink)
Broken In
 
Join Date: Oct 2008
Posts: 133
Default Re: How to put a delay in execution in a C program?

AFAIK there is no such standard function for putting delay
u have to be platform specific in this case
lucifer_is_back is offline  
Old 11-09-2009, 05:10 AM   #3 (permalink)
Wise Old Owl
 
clmlbx's Avatar
 
Join Date: Aug 2006
Location: Indore
Posts: 1,689
Default Re: How to put a delay in execution in a C program?

#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
clmlbx is offline  
Old 11-09-2009, 06:00 PM   #4 (permalink)
Right Off the Assembly Line
 
Join Date: Aug 2009
Location: Mumbai
Posts: 11
Default Re: How to put a delay in execution in a C program?

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 by xmentrio; 11-09-2009 at 06:02 PM. Reason: Automerged Doublepost
xmentrio is offline  
Old 11-09-2009, 08:25 PM   #5 (permalink)
tHe nEw gEEk......ITian
 
pr.itdude's Avatar
 
Join Date: Oct 2008
Location: New Delhi
Posts: 358
Default Re: How to put a delay in execution in a C program?

^^ +1
just include <dos.h>

and u can use this function "delay()" anywhere in any standard C program.
pr.itdude is offline  
Old 13-09-2009, 12:53 AM   #6 (permalink)
Broken In
 
Join Date: Oct 2008
Posts: 133
Default Re: How to put a delay in execution in a C program?

Quote:
Originally Posted by pr.itdude View Post
^^ +1
just include <dos.h>

and u can use this function "delay()" anywhere in any standard C program.
lucifer_is_back is offline  
Old 28-09-2009, 11:50 AM   #7 (permalink)
Right Off the Assembly Line
 
Join Date: Aug 2008
Posts: 1
Lightbulb Re: How to put a delay in execution in a C program?

Hai,
You can use delay(int n) defined in dos.h
ashik.thomas is offline  
Old 28-09-2009, 05:01 PM   #8 (permalink)
Always confused
 
vamsi360's Avatar
 
Join Date: May 2008
Location: Mandriva Control Center
Posts: 349
Smile Re: How to put a delay in execution in a C program?

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.
__________________
Vamsi Subhash
visit my blog at www.vamsisubhash.co.cc and taste a bit of IT!
vamsi360 is offline  
Old 28-09-2009, 10:50 PM   #9 (permalink)
paralinux
 
Join Date: Jul 2008
Location: Noida
Posts: 86
Default Re: How to put a delay in execution in a C program?

Quote:
Originally Posted by pr.itdude View Post
^^ +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.
anuvrat_parashar is offline  
Old 29-09-2009, 07:40 AM   #10 (permalink)
In The Zone
 
ruturaj3's Avatar
 
Join Date: Feb 2007
Location: Mumbai
Posts: 214
Default Re: How to put a delay in execution in a C program?

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.
ruturaj3 is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Charan
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 03:11 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2