lOMoARcPSD|39581265
ABSTRACT
This mini project on Calendar in C programming language is a console application
without graphics. To make the calendar look colourful, many windows properties have
been used in this project. Besides the colour used in backgrounds, the days of the month
are white and the vacations (Sundays) are indicated using the red foreground colour.
In this mini project, you can find out the day corresponding to a given date and view the
days and dates corresponding to a particular month + year. The source code is not that
long, over 400 lines. It is compiled in Code::Blocks IDE with GCC compiler.
To help you understand the calendar mini project better, there are lots of comments
within the source code. This project is aimed to teach you “how to make Calendar using
C”. Click on the link below to directly download the source code along with the
executable file.
lOMoARcPSD|39581265
INTRODUCTION
The Calendar in C Programming is a Calendar Project In C that helps you find the date and
day you need by being built in the C programming language. It also does a few other tasks. A
C-written calendar application may offer information going back to the late 1600s.
About Calendar in C:
Basically three operations can be done in this calendar application. To find out the day
corresponding to a given date, the date, month and year are asked. You can list the days and
dates of any month of any year. For example, entering 04 2014 (April 2014) will give you an
output as shown in the screenshot in this post.
You can navigate the months using arrow keys, or press ‘n’ and ‘p’ keys to view the next and
previous months respectively. The third feature of this C mini project on Calendar application
utilizes file handling. With this feature, you can add important notes with corresponding
dates.
The functions used in the source code are simple and easy to understand. The ones listed
below have been used to produce background with colour effects. They are described in the
source code with comments.
• void Set Colour (int Forg C)
• void Clear Console To Colours (int Forg C, int Back C)
• void Set Colour And Background(int Forg C, int Back C)
Describe the Calendar
It is a day-planning technique. This is done by giving names to certain time periods, most
frequently days, weeks, months, and years. A date in such a system designates a single,
particular day. A calendar is a tangible representation of such a system (typically made of
paper). A calendar can also refer to a list of forthcoming occasions, such as a court calendar,
or a collection of documents that are largely or entirely chronological, such as a wills
calendar.
Explanation
To begin, we'll create two arrays: one with the number of days in each month, and another
with all of the month names. Note that the first position in both arrays is intentionally left
empty; we want to keep things simple by using 1 to 12.
lOMoARcPSD|39581265
The user input is obtained via the first function input year(). The user is asked to enter a year.
Note that no input validation or error handling is done in order to keep things basic.
The following method, determine day code(), is used to get the day number of the first day of
that year, allowing us to display the date in the proper location. (As a result, it's just utilized
for output.)
The determine leap year() method is used to see whether the user's input is a leap year. If this
is the case, the number of days in February is increased to 29.
Each month is printed on the screen using the final function calendar(). To loop across all
months, use the first for loop. The month's name and all of the days of the week are then
printed. The day code is then used to place the prompt under the correct weekday. Then we
print a month's worth of dates. The final step is to place the prompt in the proper weekday
position.
Coding
#include<stdio.h>
#define TRUE 1
#define FALSE 0
int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char *months[]=
" ",
"\n\n\nJanuary",
"\n\n\nFebruary",
"\n\n\nMarch",
"\n\n\nApril",
"\n\n\nMay",
lOMoARcPSD|39581265
"\n\n\nJune",
"\n\n\nJuly",
"\n\n\nAugust",
"\n\n\nSeptember",
"\n\n\nOctober",
"\n\n\nNovember",
"\n\n\nDecember"
};
int inputyear(void)
int year;
printf("Please enter a year (example: 1999) : ");
scanf("%d", &year); return year;
lOMoARcPSD|39581265
int determinedaycode(int year)
int daycode;
int d1, d2, d3;
d1 = (year - 1.)/ 4.0;
d2 = (year - 1.)/ 100.; d3 = (year
- 1.)/ 400.; daycode = (year + d1 -
d2 + d3) %7; return daycode;
int determineleapyear(int year)
if(year% 4 == FALSE && year%100 != FALSE || year%400
== FALSE)
{ days_in_month[2] = 29;
return TRUE;
lOMoARcPSD|39581265
else
days_in_month[2] = 28;
return FALSE;
void calendar(int year, int daycode)
{ int month, day;
for ( month = 1; month <= 12; month++ )
{ printf("%s", months[month]);
printf("\n\nSun Mon Tue Wed Thu Fri
Sat\n" );
lOMoARcPSD|39581265
// Correct the position for the first date for
( day = 1; day <= 1 + daycode * 5; day++ ) {
printf(" ");
}
// Print all the dates for one month
for ( day = 1; day <= days_in_month[month];
day++ )
printf("%2d", day );
// Is day before Sat? Else start next
line Sun.
if ( ( day + daycode ) % 7 > 0 )
printf(" " ); else printf("\n
" );
// Set position for next month
daycode = ( daycode +
days_in_month[month] ) % 7;
lOMoARcPSD|39581265
int main(void) { int year,
daycode, leapyear;
year = inputyear(); daycode =
determinedaycode(year);
determineleapyear(year);
calendar(year, daycode);
printf("\n");
}
Output