// A macro constant called CLK_TCK defines the relation betwen clock tick and second
// (clock ticks per second).
//clock()函数Return number of clock ticks since process start
/* clock example: countdown */ #include <stdio.h> #include <time.h> void wait ( int seconds ) { clock_t endwait; endwait = clock () + seconds * CLK_TCK ; while (clock() < endwait) {} } int main () { int n; printf ("Starting countdown.../n"); for (n=10; n>0; n--) { printf ("%d/n",n); wait (1); } printf ("FIRE!!!/n"); return 0; }Output:
Starting countdown...
10
9
8
7
6
5
4
3
2
1
FIRE!!!