Pausing in C

How were programs paused in C back when there were no streams, obviously not by system("pause"); or system("cls"); :D

I am curious to know, as I am using C, and dislike using pause in every batch file I write.
Last edited on
Indefinitely with while(1) or for(;;) loops :D
Don't forget to add a way to break the loop !

Super bad clunky way with pause length dependent on computer speed:
1
2
3
int x = 0;
while(x<SOMEBIGINT)
{x++;}


A better way involves comparing the difference between a start and end 'time()' from the time.h library. This way you can set the pause time to what you want. GetTickCount() too !
Last edited on
Generally, these are OS-specific.

For example, in the WinAPI, you can use WaitForSingleObject.

Your other options are to create semaphores with threads. It can be done with the boost::thread library: http://www.boost.org/doc/libs/1_50_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref

Functions that do this are called "blocking" functions. If you google that, you'll probably find something better. Unfortunately there is nothing in std that will do this (that I know of).
C on DOS had kbhit() which wrapped a BIOS call to detect a key press. You'd need the key map to work out what key was pressed correctly, so if a different region keyboard was attached, the program would have to be told somehow.

As described above, this is specific to the Hardware (PC), OS (MS-DOS) and probably compiler too (Borland C).
There is an article on this site, which describes all the options for this sort of thing.
Topic archived. No new replies allowed.