Question: write a c program Countdown to New Year New year is coming! Let us write a program to show how much time to elapse before
write a c program



Countdown to New Year New year is coming! Let us write a program to show how much time to elapse before the New Year. The beginning of the coming New Year is definecd as Jan 1, 2018, with time at 00:00:00 for hour:minute:second. Your program should read a user input date (day and month) and time (hour, minute and second), assuming valid input values within year 2017 and the earliest possible input date and time is 00:00:01, Jan 1, 2017. Your program should then display how many days, hours, minutes and seconds before the coming New Year. A number of time library functions can be useful here. mktime() function should be used to convert input date and time to the internal time_t format. time_t mktime(struct tm *timeptr) It reads and converts the member data stored in a structure pointed to by input parameter pointer timeptr intoa time_t return value according to the local time zone. Please note that you need not fill all members in the structure to start the conversion. Basically just the date (day, month, year) and time (hour, minute, second) members are sufficient. And you may use another function difftime) to calculate the time difference between two time_t values double difftime(time t time1, time_t time2) The function returns the difference in seconds between time1 and time2 (time1-time2) And finally gmtime() function struct tm *gmtime(const time_t *timer) The value pointed by the input pointer parameter timer in the function call is analyzed in Coordinated Universal Time (UTC), also known as Greenwich Mean Time (GMT). and broken up into different human understandable date-and-time components. The results are stored into different members of a data structure of type sturct tm and returned as a pointer to such a structure. Time functions reference https://www.tutorialspoint.com/c_standard_library/time_h.htm You may assume the local time zone setting of the system is correct, although codeSubmit system is now running in time zone UTC+0 instead of UTC-8 for Hong Kong
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
