Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pausing my prog with ftime()????????

Status
Not open for further replies.

metamorphy

Programmer
Dec 16, 2001
34
US
I am currently using the following code to make my program pause 10 seconds. It then checks for the existence of a file. If the file is found the program executes a new section of code. Otherwise it keeps on checking. Unfortunately, making my program pause in this way seems to use a lot of system resources. Is there a better way to do this so that other programs that are running are not slowed down.

#include <sys/types.h>
#include <sys/timeb.h>
struct timeb xtime;
struct timeb ytime;
long time1;
long time2;

void wait10()
{
ftime(&xtime);
time1 = xtime.time;

while (!check_time())
{}
//Search for the existence of a file.

}

check_time()
{
ftime(&ytime);
time2= ytime.time;
if (time2 - time1 >= 10)
{return 1;}
else
{return 0;}
}
 
Try using sleep() instead...

Roy.
user.gif
 
I tried sleep(), but I cannot find the right header file to include. My OS is Windows98 and I am using microsoft visual c++ as a compiler. Any suggestions??
 
Well,the correct header you need to include in this case is:
&quot;windows.h&quot;.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top