Home Article Practice 用来练习的一段代码

用来练习的一段代码

2022-01-01 02:09  views:613  source:zeroishine    

typedef struct Date{
int year;
int month;
int day;
}date;
typedef struct Comment{
date pudate;
char puname[15];
char contain[200];
struct Comment *next;
}comment;
typedef struct Anews{
date pudate;
short type;
char caption[20];
char puname[15];
char contain[3200];//the limits of the eassy is 3060 char
short conum;
comment *chead;
struct Anews *next;
}anew;
char eassy[3240];
int px,py;
int backfc[hi][wid]={0};
void fillline(int x,int y,int num,int need)//the function to fill the backfc
{
x--;
y--;
while(num--)
backfc[y][x++]=need;
return;
}
void passwordput(char *p,int num)
{
int i=0;
for(i=0;i<num;i++)
{
if(*(p+i)!=0)
putchar('*');
else
putchar('_');
}
}
void startsup()
{
gotoxy(0,0);
memset(backfc,0,hi*wid*sizeof(int) );
int i,j;
for(i=0;i<=hi+1;i++)
{
for(j=0;j<=wid+1;j++)
{
if(j==0||i==0||j==wid+1||i==hi+1)
putchar('#');
else putchar(' ');
}
putchar('\n');
}
gotoxy(1,1);
printf("<-");
fillline(1,1,2,-1);
}
char withinput()//to get the input from keyborad
{
int ch;
while(1)
{
gotoxy(px,py);
ch=getch();
switch(ch)
{
case 0:{
ch=getch();
switch(ch)
{
case 72:py--;break;
case 80:py++;break;
case 75:px--;break;
case 77:px++;break;
}
if(py>hi)py--;
else if(py<1)py++;
else if(px>wid) px--;
else if(px<1) px++;
break;
}
case 13 :return 1;
case 8 :return 2;
default :return ch;
}
}
}
void spdateput(char *p)
{
int i=0;
while(i<4)
{
if(*(p+i)!=0)
putchar(*(p+i));
else
putchar('_');
i++;
}
putchar('-');
while(i<6)
{
if(*(p+i)!=0)
putchar(*(p+i));
else
putchar('_');
i++;
}
putchar('-');
while(i<8)
{
if(*(p+i)!=0)
putchar(*(p+i));
else
putchar('_');
i++;
}
}
int datetest(date *tp)
{
int mday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if(tp->year%4==0&&tp->year%100!=0)
mday[1]++;
else if(tp->year%400==0)
mday[1]++;
//
if(tp->month>12) return 0;
if(mday[tp->month-1]<tp->day) return 0;
return 1;
}
void dateinput(date *tp,int x,int y)
{
char temp[8];
int i,p;
lable9:memset(temp,0,8*sizeof(char) );
i=1,p=0;
while(i&&p<=7)
{
gotoxy(x,y);
spdateput(temp);
if(p<6&&p>=4)
gotoxy(x+p+1,y);
else if(p>=6)
gotoxy(x+p+2,y);
else if(p<4)
gotoxy(x+p,y);
lable8:i=getch();
switch(i)
{
case 224:
{
i=getch();
goto lable8;
}
case 8:if(p!=0) temp[--p]=0;break;
default:if(i<='9'&&i>='0') temp[p++]=i;break;
}
}
tp->year=(temp[0]-48)*1000+(temp[1]-48)*100+(temp[2]-48)*10+temp[3]-48;
tp->month=(temp[4]-48)*10+(temp[5]-48);
tp->day=(temp[6]-48)*10+(temp[7]-48);
if(datetest(tp) ) return;
else
{
gotoxy(x,y-1);
printf("date illgal!");
goto lable9;
}
}



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)