Why doesn't this small C program work as expected?
I've got a small C program that makes use of difftime. its really strange,
it doesn't print out the line after 10 seconds.
If however I uncomment out the sleep line then it works.
Any ideas why this is happening?
/* difftime example */
#include <stdio.h> /* printf */
#include <time.h> /* time_t, struct tm, difftime, time, mktime */
int main ()
{
time_t start, stop;
start = time(NULL);
for(; /* some condition that takes forever to meet */;) {
// do stuff that apparently takes forever.
stop = time(NULL);
double diff = difftime(stop, start);
//sleep (1);
if (diff >= 10) {
printf("10 seconds passed...");
start = time(NULL);
}
}
}
No comments:
Post a Comment