CALENDER NOTES 1.0
(C program)

299-year calendar (1801-2099). You can add notes to any date.
/* ##################################### # CALENDAR-NOTES 1.0 # # tested in Turbo C++,version 3.0 # ##############20/2/2008############## */ #include<dos.h> #include<conio.h> #include<stdio.h> #include<string.h> #include<stdlib.h> #define XPRSN_LEN 159 char msg[32][XPRSN_LEN+1]; int blank, monthDays, curXY, d, m, y, msgClearFlag;; FILE *flptr, *tmpfp; /******************** gets notes ********************/ void SaveMsg() { int d_,m_,y_; char msg_[XPRSN_LEN+1]; tmpfp=fopen("tmp.tmp","w"); rewind(flptr); while(fscanf(flptr,"%d %d %d %[^\n]\n",&d_,&m_,&y_,msg_)!=EOF) { if(m==m_&&y==y_&&d==d_) continue; else fprintf(tmpfp,"%d %d %d %s\n",d_,m_,y_,msg_); } if(msg[d][0]!=NULL) fprintf(tmpfp,"%d %d %d %s\n",d,m,y,msg[d]); fclose(flptr), flptr=fopen("caldiary.dat","w"); fclose(tmpfp), tmpfp=fopen("tmp.tmp","r"); while(fscanf(tmpfp,"%d %d %d %[^\n]\n",&d_,&m_,&y_,msg_)!=EOF) fprintf(flptr,"%d %d %d %s\n",d_,m_,y_,msg_); fclose(flptr), flptr=fopen("caldiary.dat","r");; fclose(tmpfp); } void SetCurser(int NoOfCell) { curXY+=NoOfCell; if(curXY<0 || curXY>strlen(msg[d])) curXY-=NoOfCell; } void AddDel() { int i; if(curXY==strlen(msg[d])) return; for(i=curXY; i<strlen(msg[d]); i++) msg[d][i]=msg[d][i+1]; gotoxy(1,21), cprintf("%s ",msg[d]); } void AddBksp() { if(curXY==0) return; curXY--; AddDel(); } void AddChar(char ch) { int i; if(strlen(msg[d])==XPRSN_LEN) return; for(i=strlen(msg[d]); i>=curXY; i--) msg[d][i+1]=msg[d][i]; msg[d][curXY]=ch; curXY++; gotoxy(1,21), cprintf("%s",msg[d]); } void GetXprsn() { char ch; curXY=0; textattr(16*BLACK+WHITE); while(1) { gotoxy(curXY%40+1,21+curXY/40); ch=getch(); if(ch==0) switch(getch()) { case 71: SetCurser(-curXY); continue; case 72: SetCurser(-40); continue; case 75: SetCurser(-1); continue; case 77: SetCurser(1); continue; case 79: SetCurser(strlen(msg[d])-curXY); continue; case 80: SetCurser(40); continue; case 83: AddDel(); continue; } else if(ch=='\b') AddBksp(); else if(ch=='\r') { SaveMsg(); msgClearFlag=0; return; } else AddChar(ch); } } /******************** changes date ********************/ void PutMsg() { textattr(16*BLACK+WHITE), gotoxy(1,21); if(strcmp(msg[d],"")==0) { if(msgClearFlag) return; else msgClearFlag=1; } else msgClearFlag=0; cprintf("%-*s",XPRSN_LEN,msg[d]); } void DrawDate() { int i; textbackground(BLUE); for(i=0;i<42;i++) { if(i==blank) i=monthDays+blank; gotoxy(8+4*(i%7),8+2*(i/7)), cprintf(" "); } for(i=1;i<=monthDays;i++) { textattr((d==i?4:1)*16+(msg[i][0]?15:10)); gotoxy(3+4*((blank+i-1)%7+1),8+2*((blank+i-1)/7)), cprintf(" %-2d",i); } PutMsg(); } void InitMonth() { int i, d_, m_, y_; char msg_[XPRSN_LEN+1]; int mds[]={-1, 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int tds[]={-1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; char *monthName[]={"","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"}; blank=((long)(365.25*(y-1801l))+tds[m]+4-(y>1900))%7; if(y%4==0&&y!=1900) { mds[2]=29; if(m>2) blank=(blank+1)%7; } else mds[2]=28; textattr(16*BLUE+WHITE), gotoxy(16,4), cprintf("%s %d",monthName[m],y); monthDays=mds[m]; for(i=1;i<=31;i++) msg[i][0]=NULL; rewind(flptr); while(fscanf(flptr,"%d %d %d %[^\n]\n",&d_,&m_,&y_,msg_)!=EOF) if(m==m_&&y==y_) strcpy(msg[d_],msg_); } void SetDate(int direction) { d+=direction; if(d<1 || d>monthDays) d-=direction; else DrawDate(); } void SetMonth(int direction) { m+=direction; if(m>12) { if(y==2099) { m-=direction; return; } else y++, m-=12; } else if(m<1) { if(y==1801) { m-=direction; return; } else y--, m+=12; } InitMonth(); if(d>monthDays) d=monthDays; DrawDate(); } void GetKey() { InitMonth(), DrawDate(); while(1) { textattr(0), gotoxy(1,1), cprintf(" "), gotoxy(1,1); /* Hide curser */ switch(getch()) { case 27: fclose(flptr), system("del tmp.tmp"), exit(0); case'e': case'E': GetXprsn(); break; case'8': SetDate(-7); break; case'4': SetDate(-1); break; case'6': SetDate(1); break; case'2': SetDate(7); break; case 72: SetMonth(1); break; case 75: SetMonth(-12); break; case 77: SetMonth(12); break; case 80: SetMonth(-1); break; } } } /************************************************/ void Instructions() { textmode(C80); textcolor(WHITE); cputs("_CALENDAR-NOTE INSTRUCTIONS_\n\n\r"); cputs(" >> Arrow keys to change month and year.\n\n\r"); cputs(" >> 8, 4, 6, 2 to change day(Num Lock).\n\n\r"); cputs(" >> If U want to write notes in any date \n\r"); cputs(" 1. go to that date.\n\r"); cputs(" 2. press the key 'e' or 'E'.\n\r"); cputs(" 3. now you may write the notes.\n\r"); cputs(" 4. then press Enter key."); getch(); } void DrawTable() { int i; char *dayName[]={"SUN","MON","TUE","WED","THR","FRI","SAT"}; textattr(16*BLUE+LIGHTRED); gotoxy(6,3), cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"); gotoxy(6,4), cprintf("º º"); gotoxy(6,5), cprintf("ÌÍÍÍÑÍÍÍÑÍÍÍÑÍÍÍÑÍÍÍÑÍÍÍÑÍÍ͹"); for(i=0;i<7;i++) gotoxy(6,6+2*i), cprintf("º ³ ³ ³ ³ ³ ³ º"); for(i=0;i<6;i++) gotoxy(6,7+2*i), cprintf("ÌÍÍÍØÍÍÍØÍÍÍØÍÍÍØÍÍÍØÍÍÍØÍÍ͹"); gotoxy(6,19), cprintf("ÈÍÍÍÏÍÍÍÏÍÍÍÏÍÍÍÏÍÍÍÏÍÍÍÏÍÍͼ"); textcolor(WHITE); for(i=0;i<7;i++) gotoxy(7+4*i,6), cprintf("%s",dayName[i]); } void main() { struct date dt; getdate(&dt), d=dt.da_day, m=dt.da_mon, y=dt.da_year; Instructions(); textmode(C40); DrawTable(); flptr=fopen("caldiary.dat","r"); GetKey(); } /******************************************************* * More programs: http://programs.on.googlepages.com * * Please report suggestions: programs.on@gmail.com * ********************************************307*lines**/