Solution for Exercise 21-10
ex2110
#include <stdio.h>
#include <time.h>
int main()
{
time_t now,then;
float delay=0.0;
time(&then);
puts("Start");
while(delay < 1)
{
time(&now);
delay = difftime(now,then);
printf("%f\r",delay);
}
puts("\nStop");
return(0);
}
Output
Start
1.000000
Stop
Notes
* Lamentably, on my system at least, the value is in whole seconds not fractional parts. So the effect of the while loop is to pause program execution for one second. Therefore:
* Modify the code so that the value 1 in Line 11 is changed to a higher value.
* You can also use the difftime() function to perform time math. The thought of doing so frightens me utterly.
Copyright © 1997-2025 by QPBC.
All rights reserved
