I would like to display the seconds elapsed after the start of program:
volatile time_t start_time = time(NULL);
volatile time_t target_seconds = 60*60*17;
volatile time_t time_passed = 0;
while(1)
{
time_passed = time(NULL)-start_time;
printf("\rTime elapsed=%lu/%lu(seconds)", time_passed, target_seconds);
}
Output:
Time elapsed=1/61200(second)
But it will keep updating the display no matter what value time_passed is.
Now I only want to update the displaying time elapsed when the actual time is incremented. So I changed the program in this way:
volatile time_t start_time = time(NULL);
volatile time_t target_seconds = 60*60*17;
volatile time_t time_passed = 0;
while(1){
if ((time(NULL)-start_time) != time_passed)
{
time_passed = time(NULL)-start_time;
printf("\rTime elapsed=%lu/%lu(seconds)", time_passed, target_seconds);
}
}
Now it displays nothing. Can anyone explain why and how to solve it.