日历20091016
1.查询年历2.查询月历
功能还未健全,期待评论
#include<stdio.h>
#include "conio.h"
#include<stdlib.h>
#include <conio.h>
int e[] = {0,3,3,6,1,4,6,2,5,0,3,5};
char flag;
note(int year,int month,int day)
{
long char write;
FILE *fp;
if((fp=fopen("Notebook.txt","w"))==NULL)
{
puts("\n\nThis file can not be opened");exit(0);
}
fscanf(stdin,"%s",&write);
fprintf(fp,"\n%d-%d-%d\n%s",year,month,day,write);
fclose(fp);
if((fp=fopen("NOTEBOOK.txt","r"))==NULL)
{
puts("The input file can not be opened");exit(0);
}
fscanf(fp,"%d%d%d%s",year,month,day,&write);
fprintf(stdout,"\n%d-%d-%d\n%s",year,month,day,write);
fclose(fp);
}
print(int year,int month)
{
int i, j;
printf("MON\tTUE\tWEB\tTHU\tFRI\tSAT\t\SUN\n");
if(month==2)
{
if (year%4==0&&year%100!=0||year%100==0)
{
for(i=1;i<=29;i++)
{
int rest=(i-1+e[month-1]+year+(year/4)-year/100+year/400);
--rest;
rest%=7;
if(i==1) /* 确定1号打印的位置 */
{
if(rest==0) /*判断1号是否为星期日*/
{
printf("\t\t\t\t\t\t");
}
else
{
for(j=1;j<(rest%7);j++)
{
printf("\t");
}
}
}
printf("%d\t",i);
if(rest%7==0)
printf("\n");
}
}
else
{
for(i=1;i<=28;i++)
{
int rest=(i-1+e[month-1]+year+(year/4)-year/100+year/400);
rest%=7;
if(i==1) /* 确定1号打印的位置 */
{
if(rest==0) /*判断1号是否为星期日*/
{
printf("\t\t\t\t\t\t");
}
else
{
for(j=1;j<(rest%7);j++)
{
printf("\t");
}
}
}
printf("%d\t",i);
if(rest%7==0)
printf("\n");
}
}
}
else
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
for(i=1;i<=31;i++)
{
int rest=(i-1+e[month-1]+year+(year/4)-year/100+year/400);
rest%=7;
if(i==1) /* 确定1号打印的位置 */
{
if(rest==0) /*判断1号是否为星期日*/
{
printf("\t\t\t\t\t\t");
}
else
{
for(j=1;j<(rest%7);j++)
{
printf("\t");
}
}
}
printf("%d\t",i);
if(rest%7==0)
printf("\n");
}
}
else
{
for(i=1;i<=30;i++)
{
int rest=(i-1+e[month-1]+year+(year/4)-year/100+year/400);
rest%=7;
if(i==1) /* 确定1号打印的位置 */
{
if(rest==0) /*判断1号是否为星期日*/
{
printf("\t\t\t\t\t\t");
}
else
{
for(j=1;j<(rest%7);j++)
{
printf("\t");
}
}
}
printf("%d\t",i);
if(rest%7==0)
printf("\n");
}
}
}
printf("\n");
}
notebook(int year,int month,int day)
{
}
main()
{
int month,year,day;
char menu;
menu:
system("cls");
clreol();
printf("\n\t\t\t******************************\n");
printf("\t\t\t*\t Menu *\n");
printf("\t\t\t*\t1.Year Calender *\n");
printf("\t\t\t*\t2.Month Calender *\n");
/* printf("\t\t\t*\t3.Note Book *\n"); */
printf("\t\t\t*\t3.Exit *\n");
printf("\t\t\t******************************\n");
printf("\t\t\t* please enter selection *\n");
printf("\t\t\t******************************\n");
gotoxy(51,8);
while(1)
{
menu=getch();
switch(menu)
{
case'1':
system("cls");
clreol();
printf("\n\t\t\t******************************\n");
printf("\t\t\t*\t Menu *\n");
printf("\t\t\t*\t1.Year Calender *\n");
printf("\t\t\t*\t2.Month Calender *\n");
/* printf("\t\t\t*\t3.Note Book *\n"); */
printf("\t\t\t*\t3.Exit *\n");
printf("\t\t\t******************************\n");
printf("\t\t\t*\t year: *\n");
printf("\t\t\t******************************\n");
gotoxy(43,8);
scanf("%d",&year);
nextyear:
if(flag=='n'||flag=='N')
{
year+=1;
}
previousyear:
if(flag=='p'||flag=='P')
{
year-=1;
}
system("cls");
clreol();
for(month=1;month<13;month++)
{
printf("\t\t\tYear: %d\tMonth:%d\n",year,month);
print(year,month);
}
printf("Press M to Menu N to Nextyear P to Previousyear.\nAnykey to Exit!\n");
flag=getch();
if(flag=='m'||flag=='M')
{
goto menu;
}
else if(flag=='n'||flag=='N')
{
goto nextyear;
}
else if(flag=='p'||flag=='P')
{
goto previousyear;
}
else
return;
break;
case'2':
loop:
system("cls");
clreol();
printf("\n\t\t\t******************************\n");
printf("\t\t\t*\t Menu *\n");
printf("\t\t\t*\t1.Year Calender *\n");
printf("\t\t\t*\t2.Month Calender *\n");
/* printf("\t\t\t*\t3.Note Book *\n"); */
printf("\t\t\t*\t3.Exit *\n");
printf("\t\t\t******************************\n");
printf("\t\t\t* Year:\tMonth: *\n");
printf("\t\t\t******************************\n");
gotoxy(34, 8);
scanf("%d",&year);
gotoxy(47, 8);
scanf("%d",&month);
nextmonth:
if(month>12)
{
month=1;
year+=1;
}
previous:
if(month<1)
{
month=12;
year-=1;
}
system("cls");
clreol();
printf("\n\t\t\t******************************\n");
printf("\t\t\t*\t Menu *\n");
printf("\t\t\t*\t1.Year Calender *\n");
printf("\t\t\t*\t2.Month Calender *\n");
/* printf("\t\t\t*\t3.Note Book *\n"); */
printf("\t\t\t*\t3.Exit *\n");
printf("\t\t\t******************************\n");
printf("\t\t\t* Year:%d\tMonth:%d *\n",year,month);
printf("\t\t\t******************************\n");
print(year,month);
printf("\nPress M to Menu Space to Continue N to Nextmonth P to Previousmonth.\nAnykey to Exit!\n");
flag=getch();
if(flag==' ')
{
goto loop;
}
else if(flag=='n'||flag=='N')
{
year=year;
month+=1;
goto nextmonth;
}
else if(flag=='p'||flag=='P')
{
year=year;
month-=1;
goto previous;
}
else if(flag=='m'||flag=='M')
{
goto menu;
}
else if(flag=='w'||flag=='W')
{
system("cls");
clreol();
printf("\n\t\t\t******************************\n");
printf("\t\t\t*\t Menu *\n");
printf("\t\t\t*\t1.Year Calender *\n");
printf("\t\t\t*\t2.Month Calender *\n");
/* printf("\t\t\t*\t3.Note Book *\n"); */
printf("\t\t\t*\t3.Exit *\n");
printf("\t\t\t******************************\n");
printf("\t\t\t*\t Day: *\n");
printf("\t\t\t******************************\n");
gotoxy(42,8);
fscanf(stdin,"%d",&day);
note(year,month,day);
}
else
return;
break;
case'3':
return;
break;
}
}
}
CALENDER.rar
(10.14 KB)