This is ugly, but maybe something along this line would work.
Code:
#include <stdio.h>
#include <time.h>
int main(void)
{
double duration;
time_t end, now, start = time(NULL), then = now = start;
struct tm *stop = localtime(&start);
stop->tm_hour += 1; /* one hour from now */
end = mktime(stop);
duration = end - start;
for ( ; now < end; now = time(NULL) )
{
if ( now > then )
{
double progress = now - start;
double remaining = duration - progress;
double percent = 100.0 * remaining / duration;
printf("\ruptime: %.0f seconds, %5.2f%% remaining", progress, percent);
fflush(stdout);
then = now;
}
/*
* Do real work here.
*/
}
return 0;
}