Hi I want to printf the dateApp function
For example I expected : 19:04
But the result is : 19:4
How to modify the function, so the function always return 2 digits, Thankyou!
void dateApp(){
char line[500] = "\xb3";
time_t currentTime;
time(¤tTime);
struct tm *myTime = localtime(¤tTime);
printf("Date : %i/%i/%i \xb3 Time : %i:%i %44s", myTime ->tm_mday, myTime->tm_mon + 1, myTime->tm_year + 1900, myTime->tm_hour, myTime->tm_min, line );
}
>Solution :
You need to add a field width of 2 to each %i if you want it to always print at least 2 characters, along with the 0 flag to tell it to pad with zeros on the left.
printf("Date : %02i/%02i/%i \xb3 Time : %i:%02i %44s", ...