0
How can i display on screen calendar of year in c
in python we do import calendar cal = calendar.calendar(2018) print(cal) this will display it all from jan to dec
3 ответов
+ 5
By using `struct tm`¹ structure from <time.h> as follow
// Get the current system time
time_t rawTime = time(NULL);
// Instantiating a pointer to `struct tm` structure using the current time
// 1. for getting the local system time
struct tm *local_now = localtime(&rawTime);
// 2. for getting the Greenwich mean time
struct tm *greenwich_now = gmtime(&rawTime);
// Retrieving each member object and printing out in a formatted fashion
// For local time
printf("%d/%d/%d", local_now -> tm_mon+1,
local_now -> tm_mday,
local_now -> tm_year + 1900);
Output for today:
11/18/2018
NOTE: In online-sandboxed compilers, `localtime` and `gmtime` yield the same result.
EDIT_1: To reliably print the name of the month instead of the number, constructing a lookup table would be an easy solution.
char *m_name[] = {"Jan", "Feb", ... , "Dec"};
...
printf(..., m_name[local_now -> tm_mon], ...);
EDIT_2: This just addresses the core element of a calendar system. In other words, it would be the baseline for constructing your own calendar
_____
¹ https://en.cppreference.com/w/c/chrono/tm
+ 3
A search in codeplayground delivered this beaut by Ace
https://code.sololearn.com/ceEVvt3R0P7i/?ref=app
+ 1
thanks bro