Student new to C++ and have written a program doing shuttle launch countdown which works fine. I now need to know how to wait() or sleep() for 1 second between each number as counter decrements by one. Borland compiler uses sleep in dos library. What library and command is equivalent? Found references to win32.dll etc. and no help as bloodshed not aware of that library. Sorry if this is absurd question but i have read all the faq's and hope I have asked the question properly.
Thanks
Bill
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is not the place to answer to such questions. You should ask for help concerning to this project. However, I will not be categoric and I will try to answer your question:
If you are programming for DOS in C++, you can use the clock () function that comes with ctime. The sleep program that I've made for CS Command Line Tools (my other project) uses the procedure:
The variable CLOCKS_PER_SEC returns the clock ticks per second. The function clock () returns the ticks since the program started. So you calculate the limit tick first. Then you wait until clock () reaches or passes limit_tm. This procedure is CPU consuming, but it is the only way of doing a wait that I am aware of. If you are programming for Windows, you can check for other libraries.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Student new to C++ and have written a program doing shuttle launch countdown which works fine. I now need to know how to wait() or sleep() for 1 second between each number as counter decrements by one. Borland compiler uses sleep in dos library. What library and command is equivalent? Found references to win32.dll etc. and no help as bloodshed not aware of that library. Sorry if this is absurd question but i have read all the faq's and hope I have asked the question properly.
Thanks
Bill
This is not the place to answer to such questions. You should ask for help concerning to this project. However, I will not be categoric and I will try to answer your question:
If you are programming for DOS in C++, you can use the clock () function that comes with ctime. The sleep program that I've made for CS Command Line Tools (my other project) uses the procedure:
#include <ctime>
...
void Sleep (double seconds)
{
double limit_tm = clock () + CLOCKS_PER_SEC * seconds;
while (clock() < limit_tm)
{
}
}
The variable CLOCKS_PER_SEC returns the clock ticks per second. The function clock () returns the ticks since the program started. So you calculate the limit tick first. Then you wait until clock () reaches or passes limit_tm. This procedure is CPU consuming, but it is the only way of doing a wait that I am aware of. If you are programming for Windows, you can check for other libraries.