Originally Posted by matsp
That code is weird, notice the windows Sleep function I put there. When I sleep for 265 miliseconds, ticks1 will be 265, so will ticks2 (lines 10 and 11). This is my output:
clock_t ticks1, ticks2;
ticks1 = clock();
ticks2 = ticks1;
printf("Took %ld ticks to wait one second. ticks2 = %ld, ticks1 = %ld\n",ticks2 - ticks1, ticks2, ticks1);
printf("This value should be the same as CLOCKS_PER_SEC which is %ld.\n",CLOCKS_PER_SEC);
Apparently, the loop breaks when ticks2 is 1000, and it took 735 ticks to wait one second, which is not true because CLOCKS_PER_SEC is 1000 in my computer.
Took 735 ticks to wait one second. ticks2 = 1000, ticks1 = 265
This value should be the same as CLOCKS_PER_SEC which is 1000.
Now, if I do it the way I put it, it works. And if I remove the Sleep() function, it also works. But If the program had some time running, then it doesn't work.