I've been reading sites that talk about clock() but I don't really get an answer by doing that. I mean, I still need to confirm and know some more stuff. I hope you could help me...
Here's what i would like to know:
1] what does the value returned by clock() mean?
---system clock ticks? if yes, what exactly is system clock ticks
compared to wall clock/ wristwatch clock?
2] what does the value returned by CLOCKS_PER_SEC mean?
---is its value always 1000? and is it how much the clock() value increases in a second?
3] how does these two codes differ in how they function?
---from http://www.daniweb.com/forums/thread120452.html#
if (clock() > FiveSecondsLater)
{
// Do whatever it is you want to do.
}
and this one
void wait (float seconds)
{
clock_t EndTime = seconds * CLOCKS_PER_SEC;
while (EndTime > clock())
{
// this will loop until clock() equals EndTime
}
}
---i mean, aren't they the same wait function?
4] does the first code need a loop(outside) for it to become a wait function? and if yes, what condition shall i put to it?
im trying to make dots appear in succession
and im using codeblocks
from this code...
/* clock example: countdown */
#include <stdio.h>
#include <time.h>
int n;
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
int main ()
{
printf ("Starting countdown...\n");
for (n=10; n>0; n--)
{
printf ("%d\n",n);
wait (1);
}
printf ("FIRE!!!\n");
return 0;
}
i came to this
void waiter(){
int x=0;
while(x<3){
cout<<".";
clock_t stopwait;
stopwait = clock () + 1 * CLOCKS_PER_SEC ;
while (clock() < stopwait) {}
x++;
}
}//end of waiter
the code works perfectly already but i dont know how the innermost "while" does.
i tried removing it since it does not contain codes between its braces, but doing so will alter the program~