Advertisement

How can I make a C++ Program pause for a while????

Started by March 31, 2001 09:42 PM
1 comment, last by ProgrammingMan 23 years, 10 months ago
I was just wondering how to make a C++ Program pause for a given amount of time because one of my messages just blares by on the screen and you can''t read it. If you know how either post it or email me. Thanks, ProgrammingMan chris42386@hotmail.com
If you are printing via the console (cout or printf), then its easy. Have the problem print a few lines then add a line of code, a cin statement or scanf. In these statements, just read in a dummy character. This will "pause" your output.

Something like this:
scanf("%c", &cDummyChar);

Then, when you run the program, you will see a few lines of output then you will enter a character and press enter to cause the output to resume. If you are in a loop, make a small counter that executes the sscanf about every 20 output lines or something.
Advertisement
sleep() for whole seconds or
usleep() for milliseconds.

if you don't know how many times it will get printed out, try something in manner of:
  int a = 0;while(condition)	{	 a++;	 if(a > 22)		{		 sleep(2);		 a = 0;		}	 printf("%s",blabla);	}  



/Mikael Jacobson



Edited by - mikael_j on April 1, 2001 12:06:44 PM

This topic is closed to new replies.

Advertisement