Need a new time delay function!

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 29
Reputation: Shinedevil is an unknown quantity at this point 
Solved Threads: 0
Shinedevil Shinedevil is offline Offline
Light Poster

Need a new time delay function!

 
0
  #1
Oct 24th, 2009
I need some help with delay functions,
First off, I know about windows.h, and the sleep(x) function.
But I can't use windows.h because it conflicts with my allegro.h causing my compiler to spew out errors from allegro.h everywhere.
Is there another function that i could use (Other than having to write out over 9000! loops to get the delay)?
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 481
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 58
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training
 
0
  #2
Oct 24th, 2009
Try using the <ctime> library:
http://www.cplusplus.com/reference/clibrary/ctime/time/

code for a 3 second delay:
  1. time_t start_time, cur_time;
  2.  
  3. time(&start_time);
  4. do
  5. {
  6. time(&cur_time);
  7. }
  8. while((cur_time - start_time) < 3);
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,458
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 189
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso
 
0
  #3
Oct 24th, 2009
Here is another one, but it delays process.

  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. void delay(int milliSec){
  7.  
  8. const unsigned int clk_strt = clock();
  9.  
  10. while(clock() - clk_strt < milliSec)
  11. continue;
  12. }
  13. int main(){
  14.  
  15. for(int i = 0; i < 5; i++)
  16. {
  17. delay(1000);
  18. cout<< (i+1) << " seconds has passed\n";
  19. }
  20. }
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle.
2) Problem 2[b]solved by : jonsca
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 297 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC