The code below is converting a number of seconds to the DD:HH:MM format. Instead of using printf, I would like to use snprintf. How should I print those d,h,m in the snprintf?
#include <stdio.h>
#define LONGEST 60
int main() {
int sec, h, m, s, d, temp;
char *temp_str;
int test= 2835656;
d = test / 86400; //divide the number of seconds by the number of seconds in a day
if (d < 100) {
temp = test % 86400;
temp /= 60; //
h = temp / 60; //to get "minute"
m = temp % 60; //to get "second"
} else {
d = 99;
h = 23;
m = 59;
}
printf("DD:HH:MM:%d:%d:%d\n", d, h, m); //output is DD:HH:MM:32:19:40
return 0;
}
I tried snprintf(temp_str, LONGEST, "%02s:%02s:%02s", d, h, m); but it didn't work