What exactly does clock() do?

I guess i understand that it starts as so as the program starts but in this example it loops, not as fast when the !getasynckeystate is there but still what going on. I borrow this code from somebody else and they didn't respond and this is a piece

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <string>
#include <Windows.h>
#include <ctime>


int isGameAvail = clock();
int main ()
{

while(!GetAsyncKeyState(VK_INSERT))
{

if(clock() - isGameAvail > 400)
{


isGameAvail = clock(); //-> Why is this called when it's defined?

std::cout << "Example " << std::endl;


}

system("PAUSE");
}
> Why is this called when it's defined?
¿what?
It looks like a very shoddy hack to try and control the speed that
Example 

gets printed on the terminal.

That there loop causes heavy CPU load. You should use a proper sleep()/delay() function.

Here's a Windows/POSIX solution that should work well everywhere
(See the IsKeyPressed() function)
http://www.cplusplus.com/forum/beginner/131352/#msg708089

Hope this helps.
Thanks!
Topic archived. No new replies allowed.