[C] 纯文本查看 复制代码
#include "data.h"
int a[2][13] = { { 0,31,28,31,30,31,30,31,31,30,31,30,31 },{ 0,31,29,31,30,31,30,31,31,30,31,30,31 } };
char c[7] = { 'S','M','T','W','T','F','S' };
char d[] = {'w','s','a','d','q'};
int isleapyear(Data * obj)
{
return (!(obj->y % 4) && (obj->y % 100)) || !(obj->y % 400);
}
int check(Data * obj)
{
int lp = isleapyear(obj);
return (obj->m > 0 && obj->m <= 12) && (obj->d >0 && obj->d <= a[lp][obj->m]);
}
int caldays(Data * obj)
{
int days = 0;
Data first = { 2000,0,0 };
for (; first.y < obj->y || first.m < obj->m; first.m++)
{
if (first.m == 13)
{
first.m = 0;
first.y++;
}
days += *(*(a + isleapyear(&first)) + first.m);
}
return days;
}
void intlist(Data * obj)
{
while (1)
{
printf("\nPlease enter the number:");
scanf("%d%d%d", &obj->y, &obj->m, &obj->d);
if (check(obj))
{
break;
}
}
}
void showwnl(Data * obj)
{
int i = 0, days = 0, k = 0, n = 1;
printf("func:w,s,a,d quit:q\n");
days = caldays(obj);
for (i = 0; i < 7; i++)
{
printf("%5c", *(c + i));
}
printf("\n");
for (i = 1, k = 1; k <= *(*(a + isleapyear(obj)) + obj->m); i++, n++)
{
if (i <= (days + 6) % 7)
{
printf("%5c", 32);
}
else
{
if (k == obj->d)
{
printf("[%3d]", k++);
}
else
{
printf("%5d", k++);
}
}
if (!(n % 7))
{
printf("\n");
}
}
printf("\nYou put the number:%d-%d-%d\n",obj->y,obj->m,obj->d);
printf("Tell me the next step is:");
}
int choose(char s)
{
int i = 0;
for(i = 0; i < 5; i++)
{
if(s == *(d + i))
{
return i;
}
}
return -1;
}
int returncho(Data * obj,int n)
{
int t = 1;
switch(n)
{
case 0:obj->y--;break;
case 1: obj->y++;break;
case 2:obj->m--;
if (obj->m <= 0)
{
obj->m = 12;
obj->y--;
}
break;
case 3:
obj->m++;
if (obj->m > 12)
{
obj->m = 1;
obj->y++;
}
break;
case 4:t = 0;break;
}
return t;
}
void _getchar(Data * obj)
{
int t = 1;
char a;
while (t)
{
clrscr();
showwnl(obj);
a = getch();
t = returncho(obj,choose(a));
}
clrscr();
printf("Thank you very much!enjoy it! By:wai1216\n");
}