⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calender.c

📁 DOS下的万年历算法
💻 C
字号:
/* simple Calendar */
#include <conio.h>
#include <stdio.h>
#include <dos.h>

#define ESC 0x11b
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define UP 0x4800
#define DOWN 0x5000
#define SPACE 0x3920
int input(int x,int y,char *msg);
int inkey()
{
int key=0;
if (bioskey(1)) key=bioskey(0);
return key;
}

int main()
{
int key=0;
unsigned int year;
unsigned long int day;
char month;
char maxdate[12]={31,28,31,30,31,30,31,31,30,31,30,31};
char months[12][10]={
"January","February","March","April","May","June","July","August",
"September","October","November","December" };
struct date now;
int i,vyear=1,vmonth=1;
getdate(&now);
year=now.da_year;
month=now.da_mon;
clrscr();
textcolor(YELLOW);
cprintf("Current Date:%2d/%2d/%4d",now.da_day,now.da_mon,now.da_year);
printf("\t\t");
textcolor(GREEN);cprintf("Year:");
textcolor(RED);cprintf("Left | Right   ");
textcolor(GREEN);cprintf("Month:");
textcolor(RED);cprintf("Up | Down");
textcolor(LIGHTBLUE);
gotoxy(20,2);cprintf("Monthly Magazine");
gotoxy(10,3);cprintf (" *********           *********");
gotoxy(10,11);cprintf(" *****************************");
gotoxy(10,4);cprintf(" Sun Mon Tue Wed Thu Fri Sat ");
textcolor(WHITE);
gotoxy(12,12);cprintf("Press SAPCE to Specify Year.");
while(key != ESC )
{
key=0;
   if ( !(year%4) && year%100 || !(year%400) ) maxdate[1]=29;
   else maxdate[1]=28;
day=year-1+(year-1)/4-(year-1)/100+(year-1)/400+1;
   for(i=0;i<month-1;i++) day+=maxdate[i];
if (vyear)
   {gotoxy(8,2);textcolor(RED);cprintf("      %5u ",year);}
if(vmonth)
   {gotoxy(21,3);textcolor(WHITE);cprintf("%-10s\n",months[month-1]);}
   if (vyear || vmonth)
   {
   textcolor(LIGHTBLUE);
   gotoxy(1,5);clreol();
   gotoxy(1,10);clreol();
   gotoxy(12+(int)(day-day/7*7)*4,5);
    for (i=1;i<=maxdate[month-1];i++)
    {
    cprintf("%3d ",i);
     if ( day-day/7*7==6) printf("\n\t   ");
    day++;
    }
   clreol();
   vyear=vmonth=0;
    }
    while( key!=ESC && key!=SPACE &&
    key!=LEFT && key!=RIGHT && key!=UP && key!=DOWN) key=inkey();
switch(key)
{
case    UP:
     if( month==1) {if (year>1) {vmonth=12;vyear=year-1;} }
     else vmonth=month-1;break;
case DOWN:if(month==12) {if (year<65535){ vmonth=1;vyear=year+1; } }
     else vmonth=month+1;break;
case LEFT:if (year>1) vyear=year-1;break;
case RIGHT:if (year<65535) vyear=year+1;break;
case SPACE: textcolor(GREEN);
      vyear=input(13,13,"Enter year:");
      gotoxy(1,13);clreol();
      if (vyear) year=vyear;
      else vyear=year; /* for refresh */
}
if (vyear) year=vyear;
if (vmonth) month=vmonth;
}
textcolor(LIGHTGRAY);
clrscr();
return 1;
}
int input(int x,int y,char *msg)
{
char pc=0;
unsigned int n=0;
gotoxy(x,y);cprintf("%s",msg);
while( (pc!=13 || n==0 ) && pc!=27 )
{
   do{
   pc=getch();
   }while( !(pc>=48 && pc<=57 || pc==8 || pc==13 || pc==27) );
    if ( pc>=48 && pc<=57)
    {
    if (pc==48 && n==0 || (long)n*10+pc-48 > 65535 ) continue;
             cprintf("%c",pc);
    n=n*10+pc-48;
    pc=0;
    }
   if (pc==8 && n>0)
   {
   printf("\b \b");
   n/=10;
   pc=0;
   }
if (pc==27) n=0;
}
return n;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -