I'm trying to write a program which will always loop.
Besides that, i also use a function called wait() within the loop.
The wait() function is to make sure the loop runs once each second.
But one problem arise:
The program used up all my CPU usage until 98% all the time!

My program is look like this:
while(condition == true)
{
//codes
wait();
}

It's there any programming method which will save more CPU usage while using a loop?

change the wait function to use less cpu by using the Sleep, SleepEx or usleep(linux) commands. Note that the precision of these functions might sometimes be worse than 10ms, so if you need accurate timing, you might wish to use a good timebase in conjuction with these functions.

It's works!
But when i run the source code, i found that windows.h must be included before conio.h. If not it will be a redefine function error.
Why?

Anyway, thanks again dougy83!
U saved my day!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.