DOS下万年历TC源代码

CRAZII@CSDN 

 

这个好像是大二时写的..用的TC(!....) 没有注释...
以前发在MSN SPACE 上的.最近整理硬盘的时候发现已经从硬盘上删除了..
所以在这发一份..省得以后再也找不到了.
重新看了一下运行效果,字符界面
上下左右键可以改年月,空格是跳转年份.


/* Xiaofeng @2005.10.25 */
/* 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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值