Calendar In C With Source Code

The calendar application in c is develop in C programming language, and this Calendar Project In C helps in finding out the date and day you want to know about. Also, it comes with some extra features.

Moving on, a calendar application In C provide the data starting from the late 1600’s. You can also directly get the day result by submitting the values. You can also add notes. The note field is 50 character maximum.

However, this calendar application project In C also includes a downloadable Calendar In C source code for free, just find the downloadable source code below and click to start downloading.

Calendar In C Programming With Sour...
Calendar In C Programming With Source Code Free Download | C project with source code

Anyway, to start creating a Calendar In C Programming, make sure that you have code blocks or any platform of c language installed in your computer.

Plus, read or visit the other interesting languages used in calendar.

Project information and Recommended Tools Used

ABOUT PROJECTPROJECT DETAILS
Project Name : Calendar In C Programming
Project Platform :C/C++
Programming Language Used:C Programming Language
IDE Tool (Recommended):Dev-C++/Code blocks
Project Type :Console Application
Calendar In C Programming with Source Code Information

What is the main use of C?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of learning any other programming language. Operating systems and diverse application software for computer architectures ranging from supercomputers to PLCs and embedded systems are examples of such applications.(According to Use of C Language | Simplilearn)

How to create a Calendar Program in C?

Time needed: 5 minutes.

Here are the steps on how to a Calendar application In C?

  • Step 1: Create a new project.

    First open the code blocks IDE and click “create a new project“.

    calendar project

  • Step 2: Choose console application.

    Second click the “console application” and after that click “next“.
    calendar console

  • Step 3: Choose C language.

    Third choose “C language” and click “next“.
    calendar console c

  • Step 4: Name Your Project.

    Fourth name the project you’ve created and click “next” after that click “finish“.
    calendar project title

  • Step 5: The actual code.

    You are free to copy the given source code below or download the downloadable source code given.

Modules and Codes Function

The Code Given Below Is For Number of Days Module

In this module which is getting the number of days example 22, 23, 24, 25, 26, 27, 28, 29, 30, 31.

int getNumberOfDays(int month,int year){ //returns the number of days in given month
   switch(month){                          //and year
      case 1 : return(31);
      case 2 : if(check_leapYear(year)==1)
		 return(29);
	       else
		 return(28);
      case 3 : return(31);
      case 4 : return(30);
      case 5 : return(31);
      case 6 : return(30);
      case 7 : return(31);
      case 8 : return(31);
      case 9 : return(30);
      case 10: return(31);
      case 11: return(30);
      case 12: return(31);
      default: return(-1);
   }
}

The Code Given Below Is For The Day Name

In this module which is getting the name of each day such as Sun, Mon, Tue, wed, thu, fri, Sat(Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday).

char *getName(int day){ //returns the name of the day
   switch(day){
      case 0 :return("Sunday");
      case 1 :return("Monday");
      case 2 :return("Tuesday");
      case 3 :return("Wednesday");
      case 4 :return("Thursday");
      case 5 :return("Friday");
      case 6 :return("Saturday");
      default:return("Error in getName() module.Invalid argument passed");
   }
}

The Code Given Below Is For The Each Number of Day Module

In this module which is getting each number of day.

int getDayNumber(int day,int mon,int year){ //retuns the day number
    int res = 0, t1, t2, y = year;
    year = year - 1600;
    while(year >= 100){
        res = res + 5;
        year = year - 100;
    }
    res = (res % 7);
    t1 = ((year - 1) / 4);
    t2 = (year-1)-t1;
    t1 = (t1*2)+t2;
    t1 = (t1%7);
    res = res + t1;
    res = res%7;
    t2 = 0;
    for(t1 = 1;t1 < mon; t1++){
        t2 += getNumberOfDays(t1,y);
    }
    t2 = t2 + day;
    t2 = t2 % 7;
    res = res + t2;
    res = res % 7;
    if(y > 2000)
        res = res + 1;
    res = res % 7;
    return res;
}

The Code Given Below Is For The Print Month Module

When using this module, which is responsible for displaying and printing all of the months.

void printMonth(int mon,int year,int x,int y){ //prints the month with all days
    int nod, day, cnt, d = 1, x1 = x, y1 = y, isNote = 0;
    if(!(mon>=1 && mon<=12)){
        printf("INVALID MONTH");
        getch();
        return;
    }
    if(!(year>=1600)){
        printf("INVALID YEAR");
        getch();
        return;
    }
    gotoxy(20,y);
    print_date(mon,year);
    y += 3;
    gotoxy(x,y);
    printf("S   M   T   W   T   F   S   ");
    y++;
    nod = getNumberOfDays(mon,year);
    day = getDayNumber(d,mon,year);
    switch(day){ //locates the starting day in calender
        case 0 :
            x=x;
            cnt=1;
            break;
        case 1 :
            x=x+4;
            cnt=2;
            break;
        case 2 :
            x=x+8;
            cnt=3;
            break;
        case 3 :
            x=x+12;
            cnt=4;
            break;
        case 4 :
            x=x+16;
            cnt=5;
            break;
        case 5 :
            x=x+20;
            cnt=6;
            break;
        case 6 :
            x=x+24;
            cnt=7;
            break;
        default :
            printf("INVALID DATA FROM THE getOddNumber()MODULE");
            return;
    }
    gotoxy(x,y);
    if(cnt == 1){
        SetColor(12);
    }
    if(checkNote(d,mon)==1){
            SetColorAndBackground(15,12);
    }
    printf("%02d",d);
    SetColorAndBackground(15,1);
    for(d=2;d<=nod;d++){
        if(cnt%7==0){
            y++;
            cnt=0;
            x=x1-4;
        }
        x = x+4;
        cnt++;
        gotoxy(x,y);
        if(cnt==1){
            SetColor(12);
        }else{
            ClearColor();
        }
        if(checkNote(d,mon)==1){
            SetColorAndBackground(15,12);
        }
        printf("%02d",d);
        SetColorAndBackground(15,1);
    }
    gotoxy(8, y+2);
    SetColor(14);
    printf("Press 'n'  to Next, Press 'p' to Previous and 'q' to Quit");
    gotoxy(8,y+3);
    printf("Red Background indicates the NOTE, Press 's' to see note: ");
    ClearColor();
}

The Code Given Below Is For The Add Note Module

In this module which is adding note like the user need to enter the date, note and the system will give you the message if it is successful or fail to save.

void AddNote(){
    FILE *fp;
    fp = fopen("note.dat","ab+");
    system("cls");
    gotoxy(5,7);
    printf("Enter the date(DD/MM): ");
    scanf("%d%d",&R.dd, &R.mm);
    gotoxy(5,8);
    printf("Enter the Note(50 character max): ");
    fflush(stdin);
    scanf("%[^\n]",R.note);
    if(fwrite(&R,sizeof(R),1,fp)){
        gotoxy(5,12);
        puts("Note is saved sucessfully");
        fclose(fp);
    }else{
        gotoxy(5,12);
        SetColor(12);
        puts("\aFail to save!!\a");
        ClearColor();
    }
    gotoxy(5,15);
    printf("Press any key............");
    getch();
    fclose(fp);
}

The Code Given Below Is For The Showing Note Module

The notes are being shown or displayed by this module, which is showing or displaying them. The system will message if it is error in opening the file. If successful the system will message note is found.

void showNote(int mm){
    FILE *fp;
    int i = 0, isFound = 0;
    system("cls");
    fp = fopen("note.dat","rb");
    if(fp == NULL){
        printf("Error in opening the file");
    }
    while(fread(&R,sizeof(R),1,fp) == 1){
        if(R.mm == mm){
            gotoxy(10,5+i);
            printf("Note %d Day = %d: %s", i+1, R.dd,  R.note);
            isFound = 1;
            i++;
        }
    }
    if(isFound == 0){
        gotoxy(10,5);
        printf("This Month contains no note");
    }
    gotoxy(10,7+i);
    printf("Press any key to back.......");
    getch();

}

The Code Given Below Is For The Main Module

In this module which is the main module of the system. The screen will display the menu which is find out the day, print all the day of month, add note and exit.

int main(){
    ClearConsoleToColors(15, 5);
    SetConsoleTitle("Calender Project - ITSOURCECODE.COM");
    int choice;
    char ch = 'a';
    while(1){
        system("cls");
        printf("1. Find Out the Day\n");
        printf("2. Print all the day of month\n");
        printf("3. Add Note\n");
        printf("4. EXIT\n");
        printf("ENTER YOUR CHOICE : ");
        scanf("%d",&choice);
        system("cls");
        switch(choice){
            case 1:
                printf("Enter date (DD MM YYYY) : ");
                scanf("%d %d %d",&date.dd,&date.mm,&date.yy);
                printf("Day is : %s",getDay(date.dd,date.mm,date.yy));
                printf("\nPress any key to continue......");
                getch();
                break;
            case 2 :
                printf("Enter month and year (MM YYYY) : ");
                scanf("%d %d",&date.mm,&date.yy);
                system("cls");
                while(ch!='q'){
                    printMonth(date.mm,date.yy,20,5);
                    ch = getch();
                    if(ch == 'n'){
                        increase_month(&date.mm,&date.yy);
                        system("cls");
                        printMonth(date.mm,date.yy,20,5);
                    }else if(ch == 'p'){
                        decrease_month(&date.mm,&date.yy);
                        system("cls");
                        printMonth(date.mm,date.yy,20,5);
                    }else if(ch == 's'){
                        showNote(date.mm);
                        system("cls");
                    }
                }
                break;
            case 3:
                AddNote();
                break;
            case 4 :
                exit(0);
        }
    }
    return 0;
}

Downloadable Source Code

Summary

This System Project is being develop in C programming language, and this simple project can enhance the knowledge of the beginners or the students to develop their skills in programming, also this project is easy to understand the module and their variables.

Inquiries

If you have any questions or suggestions about Calendar In C Programming  , please feel free to leave a comment below.

1 thought on “Calendar In C With Source Code”

  1. What is the hardware and software specifications of calender project in c . ?
    Is only one module is used in this project?

    Reply

Leave a Comment