im new to c programming. i need help im trying to get my c programs to pause for an amount of seconds and than keep going. i dont know if this is possible but if it is please tell me how.
im new to c programming. i need help im trying to get my c programs to pause for an amount of seconds and than keep going. i dont know if this is possible but if it is please tell me how.
Hm... I seem to recall something about this. Eh, it's funny how I can't quite recall where...
There are numerious ways to do this. None of them are an ANSI standard. (IE: There is no simple pause function.) Your best bet is to simply capture the time in a loop and while the current time is less than time + N seconds, keep looping.
Quzah.
Last edited by quzah; 06-18-2002 at 05:57 PM.
Hope is the first step on the road to disappointment.
Quzah, Why don't you change carreers and become a komic genius. Posts like that belong in a hall of fame.
Demonographic rhinology is not the only possible outcome, but why take the chance
Code:/* Function: Wait(int seconds) Purpose: Provide a predetermined pause in the program giving the user enough time to read a message. Continue program execution after time is up without any user interaction. Usage: Wait(3) - Pauses for 3 seconds Wait(5) - Pauses for 5 seconds */ #include <time.h> void Wait ( int seconds ); void Wait ( int seconds ) { clock_t endtime = clock() + Seconds * CLOCKS_PER_SEC; while ( ( clock() < endtime ) ); }
The world is waiting. I must leave you now.
This kind of code will only eat-up CPU resources. In a multithreaded application, this will only make things worse. The best bet is 'sleep()' (if it is supported) which will block the thread until that many number of seconds, and there will be no load at all on the CPU.