Mini project “Calendar Application” in C – Free Code Download.

Mini project “Calendar Application” is also a simple project built in C. This project has following features.

  1. It displays a nicely formatted calendar of every month.
  2. You can find the day by entering the day, month and year. For example, if you enter day = 10, month = 03 and year = 1991, it gives you the day ‘Sunday’.
  3. You can add the note for a particular day.
  4. If the given month has a note in it, it will display || in that day.

You can play with the source code and modify as per your need. Please remember it is just a sample project. Do not submit it as it is, as a part of your project. The source code for this project is also available on GitHub.

Here are the full lists of the Mini Projects in C/C++

#include <stdio.h>
#include <stdlib.h>
 
int isLeapYear( int year );        /* True if leap year */
int leapYears( int year );         /* The number of leap year */
int todayOf( int y, int m, int d); /* The number of days since the beginning of the year */
long days( int y, int m, int d);   /* Total number of days */
void calendar(int y, int m);       /* display calendar at m y */
int getDayNumber(int d,int m,int y);
char *getName(int day);
 
// Copied from 
// https://stackoverflow.com/questions/35103745/read-a-string-as-an-input-using-scanf
void flush()
{
    int c;
    while ((c = getchar()) != '\n' && c != EOF);
}
 
typedef struct {
  int day;
  int month;
  int year;
  char note[255];
} Note;
 
int main(int argc, char* argv[]){
    int year,month, day;
    char choice;
    Note note;
    FILE *fp;
 
    fp = fopen("note.bin", "r");
    if (fp == NULL) {
      fp = fopen("note.bin", "w");
    } 
    fclose(fp);
 
    while(1) {
      printf("1. Find the day\n");
      printf("2. Print calendar of a month\n");
      printf("3. Add Note\n");
      printf("4. Exit\n");
      printf("Enter your choice: ");
      scanf("\n%c", &choice);
      switch(choice) {
        case '1':
        printf("Enter the day, month and year: ");
        scanf("%d %d %d", &day, &month, &year);
        printf("The day is : %s\n", getName(getDayNumber(day, month, year)));
        break;
        case '2':
        printf("Enter the month and year: ");
        scanf("%d %d", &month, &year);
        printf("Please enter 's' to see the notes\n Press any other key to continue\n");
        calendar(year, month);
        break;
        case '3':
        printf("Enter the day, month and year: ");
        scanf("%d %d %d", &note.day, &note.month, &note.year);
        flush();
        printf("Enter the note: ");
        fgets(note.note, 255, stdin);
        fp = fopen("note.bin", "a+");
        if (fp == NULL) {
          printf("File note.bin can not be opened\n");
          exit(1);
        }
        fwrite(&note, sizeof(Note), 1, fp);
        printf("Note added sucessfully\n");
        fclose(fp);
        break;
        case '4':
        printf("Bye!!");
        exit(0);
        break;
        default:
        printf("Not a valid option\n");
        break;
      }
    }
    return 0;
}
 
int isLeapYear( int y ){
    return(y % 400 == 0) || ((y % 4 == 0) && (y % 100 != 0));
}
 
int leapYears( int y ){
    return y/4 - y/100 + y/400;
}
 
int todayOf( int y, int m, int d) {
    static int DayOfMonth[] = 
        { -1,0,31,59,90,120,151,181,212,243,273,304,334};
    return DayOfMonth[m] + d + ((m>2 && isLeapYear(y))? 1 : 0);
}
 
long days( int y, int m, int d){
    int lastYear;
    lastYear = y - 1;
    return 365L * lastYear + leapYears(lastYear) + todayOf(y,m,d);
}
 
void calendar(int y, int m){
    FILE *fp;
    Note* notes, note;
    int len, j, hasNote = 0;
    char choice;
    const char *NameOfMonth[] = { NULL/*dummp*/,
        "January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December"
    };
    char Week[] = "Su   Mo   Tu   We   Th   Fr   Sa";
    int DayOfMonth[] =
        { -1,31,28,31,30,31,30,31,31,30,31,30,31 };
    int weekOfTopDay;
    int i,day;
 
    weekOfTopDay = days(y, m, 1) % 7;
 
    fp = fopen("note.bin", "rb");
    if (fp == NULL) {
      printf("Couldn't read notes\n");
    }
    len = 0;
    while(fread(&note, sizeof(Note), 1, fp)) {
      if (note.year == y && note.month == m) {
        len++;
      }
    }
    rewind(fp);
    j = 0;
    notes = (Note*) malloc (sizeof(Note) * len);
    while(fread(&note, sizeof(Note), 1, fp)) {
      if (note.year == y && note.month == m) {
        notes[j] = note;
        j++;
      }
    }
 
    fclose(fp);
 
    if(isLeapYear(y))
        DayOfMonth[2] = 29;
    printf("\n     %s %d\n%s\n", NameOfMonth[m], y, Week);
 
    for(i=0;i<weekOfTopDay;i++)
        printf("   ");
    for(i=weekOfTopDay,day=1;day <= DayOfMonth[m];i++,day++){
        hasNote = 0;
        for (j = 0; j < len; j++) {
          if (notes[j].day == day) {
            printf("|%2d| ",day);
            hasNote = 1;
            break;
          }
        }
        if (hasNote == 0) {
          printf("%2d   ",day);
        }
        if(i % 7 == 6)
            printf("\n");
    }   
    printf("\n");
    scanf("\n%c", &choice);
    if (choice == 's') {
      printf("Here are list of notes for %d %d\n", m, y);
      for (j = 0; j < len; j++) {
        printf("%d: %s\n", notes[j].day, notes[j].note);
      }
    } else {
      return;
    }
}
 
int getDayNumber(int d, int m, int y){ //retuns the day number
    static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
    y -= m < 3;
    return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
 
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: Invalid Argument Passed");
   }
}
SHARE Mini project “Calendar Application” in C – Free Code Download.

You may also like...

65 Responses

  1. Anonymous says:

    where is the programme snippet

  2. this is a link to download the code at the end of the post.

  3. Anonymous says:

    Hi, I do think this iѕ a gгeat wеbsite.
    Ι ѕtumbledupon it 😉 I am goіng to revisit once аgаin sinсе I book marκеԁ it.
    Money and freeԁom is thе greatest ωау
    tο change, may yоu be гіch anԁ
    contіnuе to helр otheгѕ.

    Hi I am sо gгаtеful I found уour sitе, I really found you by error, while I wаs
    browsіng on Yahοο for somethіng else, Αnyhow I am here now anԁ ωould juѕt
    lіκe to ѕay thank you fοr a rеmarkаble poѕt and a
    all round enјoyаblе blog (I alsο love the thеmе/deѕign), I ԁοn’t have
    time to gο through it all at thе minute but I have bookmarkеd іt and аlsο addеd yοuг RSЅ
    fеeds, so when ӏ have tіme I will be bасk tο
    reaԁ moгe, Рlеasе ԁo keep uρ the fantаstic
    work.
    Feel free to surf my webpagesulaman

  4. Anonymous says:

    Hello
    Mit vollen Respekt , wie Sie einfach und verständlich und kompakt bie Nummerische Mathematik dargestellt haben und weiter so, ich wünsche Ihnen viel Erfolg
    Marouf

  5. Anonymous says:

    hello there, calender program is well build but how to run the same program within turbo c editor, because after adding all required header files still there are 15 errors.

    so please let me know the steps to run the source file

    thanks

  6. You must remove #include from the file. Also you don't need the definition of gotoxy, color function and background function, delete all of them becoz torbo c has all those features as builtin function

  7. Spandana J says:

    Hai…in calender progamme we got Declaration Syntax error in The place of Coord xy={0,0}

    Thanking You

  8. You must include windows.h header file. Coord is typedef structure defined under windows.h. This may help to reduce error

  9. Spandana J says:

    Even Though we got same error

  10. Hai…in calender progamme we got Declaration Syntax error in The place of Coord xy={0,0}
    please reply

    Thanking You

  11. Hey,tell me that how can i run this program in Turbo C and
    if it will not run in turbo C then then which compiler i have to use to run this program..
    reply me

  12. Ya you can modify the code so that it can run under turbo C compiler .But I suggest you to compile it under MinGW GCC compiler. Just download the Code::Blocks IDE from http://www.codeblocks.org/downloads which contains GCC compiler and compile the code.

  13. hey,thank you i got that…. but i also want to run that program in Turbo C…as u saying that to remove the definition of gotoxy, color function and background function but still there is problem of linker erros…and also windows.h file is not included in Turbo C.
    so tell me what i have to do…

  14. hey,there are three options Binaries,Source,SVN which one i have to select…please tell me, i am confused…

  15. You should download Binaries

  16. Windows.h is only for windows and gcc, it is neither in Turbo C nor in linux or Mac. You should remove windows.h

  17. got Declaration Syntax error in The place of Coord xy={0,0}
    then….

  18. In turbo C you don't need the declaration of Coord because it is only defined in windows.h. Just erase the line Coord xy = {0, 0} and run

  19. sukruthi says:

    can u send any project on c with abstract and sourse code….

  20. Anonymous says:

    i hav got error in number 2.. plz fix it…

  21. Ist error message is "Unable to open #include WINDOWS.H".

  22. In my pc it is giving 25 errors, starting with undefined symbol xy!

  23. unable to open dates its giving error for the entire years

  24. i want to create a 100 year calander at my own so please help me in doing so.

  25. Make sure you ran this project on windows with MinGW GCC compiler

  26. windows.h is only available in Windows machine, if will definitely get error if run in other machine

  27. Hello Pidugu the error is due to the missing file. IF you add some notes first and then open the calendar it works. This is simple logical error.

  28. i need code of this program

  29. sir bibek subedi
    while adding notes it takes only dd and mm so when we want to see that note we are not able to see that
    i think this is because it is not taking year as parameter as without knowing the year how it could identify that in which dd mm and year the note is added

  30. Anonymous says:

    Will this work on turbo c++

  31. Nilesh says:

    Great Website, I found my project.

  32. Anonymous says:

    Please Do Write Programs that Works On Linux…please because Students Use Linux for Programming…

  33. will this code work on visual studio c++?

  34. no Bakhtawer it doesn't on on visual studio

  35. How can I get codings of app??

  36. Met Saram says:

    Hello , Admin I have some Error in Code block
    Undeclared scanf("%d %d %d",&date.dd,&date.mm,&date.yy);
    How can I do ?

  37. Anonymous says:

    the link is not working

  38. Hey Bibek Subedi I have this assignment that I love for you to help me with1. Create a simple bike racing game that allows the user to escape from onscreen obstacles to reach the finish line. The game should have a minimum of 2 levels; An onscreen menu; and. instructions on how to play

  39. Unknown says:

    @Bibek Subedi ?????

  40. swathi says:

    search in google calendar mini project in c

  41. swathi says:

    approve my request

  42. swathi says:

    need an abstract

  43. need an abstract for this program

  44. swathi says:

    need an abstract for this program

  45. sir please send me the code for this calendera
    email id:) [email protected]

  46. Anonymous says:

    Is there something wrong with the link? It seems to have expired.

  47. could you plz send me the source code

  48. Unknown says:

    sir how can i get the code

  49. Anonymous says:

    where is code?

  50. Unknown says:

    where is download link of code

  51. Which data structure is used here

  52. Which data structure is used here

  53. I added a note but it isn't getting displayed.

  54. Unknown says:

    Nyc sir ….i am in the first year student at computer science unviersity (software engineering)
    .
    Thanks for the source code

  55. RAJ SONAM says:

    note file is not working

  56. manisai says:

    I want report for this calender program

  57. jafar says:

    sir, please send me the source code for calendar program

Leave a Reply

Your email address will not be published.

Share