我的问题,很菜
我是一个c的新手,有好多东西注意的不够。
这是我写的一个数天数的东西。但总不对,我不知怎了,还请大家多多帮忙。
可能有好多处错误,还请大家多多费心。
谢谢。
# include <stdio.h>
# define PP printf
# define FF "ERROR.Year%d,Day%d\n"
struct time
{
int year;
int mouth;
int day;
};
int calculus ( struct time *p)
{
int judge,i,date;
if ( p->mouth==1&&p->day>31)
PP(FF,p->mouth,p->day);
if ( p->mouth==3&&p->day>31)
PP(FF,p->mouth,p->day);
if ( p->mouth==5&&p->day>31)
PP(FF,p->mouth,p->day);
if ( p->mouth==7&&p->day>31)
PP(FF,p->mouth,p->day);
if ( p->mouth==8&&p->day>31)
PP(FF,p->mouth,p->day);
if ( p->mouth==10&&p->day>31)
PP(FF,p->mouth,p->day);
if ( p->mouth==12&&p->day>31)
PP(FF,p->mouth,p->day);
if ( p->mouth==4&&p->day>30)
PP(FF,p->mouth,p->day);
if ( p->mouth==6&&p->day>30)
PP(FF,p->mouth,p->day);
if ( p->mouth==9&&p->day>30)
PP(FF,p->mouth,p->day);
if ( p->mouth==11&&p->day>30)
PP(FF,p->mouth,p->day);
if ( p->year%4==0 )
judge=1;/*If "judge" is 1,this is leap year.*/
if (judge==1){
if(p->mouth==2&&p->day>29)
PP(FF,p->mouth,p->day);
for (i=1;i<p->mouth;++i){
if ( i==1||i==3||i==5||i==7||i==8||i==10||i==12 )
date=date+31;
if ( i==4||i==6||i==9||i==11)
date=date+30;
if ( i==2 )
date=date+29;
}
date=date+p->day;
}
if (judge!=1){
if(p->mouth==2&&p->day>28)
PP(FF,p->mouth,p->day);
for (i=1;i<p->mouth;++i){
if ( i==1||i==3||i==5||i==7||i==8||i==10||i==12 )
date=date+31;
if ( i==4||i==6||i==9||i==11)
date=date+30;
if ( i==2 )
date=date+28;
}
date=date+p->day;
}
return(date);
}
main()
{
struct time a;
int result;
scanf("%d,%d,%d",&a.year,&a.mouth,&a.day);
result=calculus( &a );
PP("date%d",result);
return(0);
}