Sure, here's an example C program that demonstrates the working of strftime() function:
Here's a brief explanation of how the program works:
We first declare a time_t variable current_time to hold the current time, and a struct tm pointer time_info to hold the broken-down time information.
- We use the time() function to get the current time and store it in current_time.
- We use the localtime() function to convert current_time to a struct tm object and store it in time_info.
- We declare a character array time_string of size 50 to hold the formatted time string.
- We use the strftime() function to format the time string according to our desired format. In this case, we're formatting it to display the current date and time in a human-readable format.
- Finally, we print the formatted time string using printf().
Output:
Today is Sunday, February 19, 2023. The time is 12:30 PM.
Note that the output may vary depending on the current date and time.