I need to print out the current date in the following format : Today is Wednesday – September 7, 2012. I know I will have to use the struct
struct tm* time_info;
I can easily accomplish this using strftime(), however, I am tasked to NOT use strftime() and extract members of the struct directly using printf statements. I cannot seem to get it to properly work. Any clues? Here is my current code:
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
#include <stdlib.h>
/* localtime example */
#include <stdio.h>
#include <time.h>
int main (void)
{
time_t t;
char buffer[40];
struct tm* tm_info;
time(&t);
tm_info = localtime(&t);
strftime(buffer, 40, " Today is %A - %B %e, %Y", tm_info);
puts(buffer);
return 0;
}
Instead of
strftime(buffer, 40, " Today is %A - %B %e, %Y", tm_info);
I need
printf("Today is %s, struct members info in the correct format);
The struct tm has at least these members
So now you can do e.g.
This ofcourse will print out the month and week day as numbers, I’ll leave it up to you to create a simple lookup table to get the matching English word. Use an array so you can map e.g. index 0 to “Sunday” , index 1 to “Monday” and so on.