Hi all together,
first of all I must fully agree, that the book is really great! Thanks for that!!
When I tried to solve the challenge I was struggling with the task itself. So when I finally understood what to do I found a solution.
What I didn’t like so far was the date and also the time format like 3-4-2012 12:2:3. I’d prefer 03-04-2012 12:02:03. Then I played around with the formats we learned so far.
Surprisingly the following line of code did the job for me:
printf("The shifted time will be %.2d.%.2d.%d %.2d:%.2d:%.2d\n", shiftedTime.tm_mday, shiftedTime.tm_mon+1, shiftedTime.tm_year + 1900, shiftedTime.tm_hour, shiftedTime.tm_min, shiftedTime.tm_sec);
So using %.2d also added the leading zero. So far I only understood that it formats decimal numbers always fix with two decimals. Could someone explain me why it also adds the leading zeros??