-
Time Pause
Hi I was wondering how I could have a pause in the program for a certain amount of time. Something like this:
Code:
#include <stdio.h>
#include <time.h>
#include <iostream>
using namespace std;
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
void main()
{
text=getfile(filename);
cout << "Please wait";
foutopen(filename);
for(int c=0;c<3;c++)
{
cout << ". ";
wait(1);
}
letterfrequency(letfreq, text);
getwords(words, text);
sort(words,0,words.length()-1);
apvector <int> wordfreq(words.length(),-1);
wordfrequency(wordfreq, words);
output(letfreq, wordfreq, words, filename);
}
ignore the apvector and apstring stuff (it's a school program and they're gay and make me use it...
I found this wait function at cplusplus.com and it worked by itself but when i put it into this code it doesn't work right. Any help would be greatly appreciated
-
I can't find the problem, so try replacing it with this
Code:
void wait ( long seconds ) {
clock_t limit, now = clock();
limit = now + seconds * CLOCKS_PER_SEC;
while ( limit > now )
now = clock();
}
(taken from
http://faq.cprogramming.com/cgi-bin/...&id=1043284392 )
EDIT
If you can, using a nonstandard funtion is better to spare your poor cpu
-
Thanks for the help, but i just figured out what was wrong. It kept the other stuff in the output buffer so... Code:
cout << "Please wait";
for(int c=0;c<3;c++)
{
cout << ". ";
cout.flush();
wait(.5);
}
works. Thanks