c语言时间错误的是什么意思,输入今天的日期,求明天的日期,出错了,不知怎么回事...

#include

//#include

struct date

{

int year;

int month;

int day;

};

void main()

{

void cf(struct date *p);

struct date s1,*p;

printf("请输入今天的日期:  ");

while(scanf("%d %d %d",&s1.year,&s1.month,&s1.day))

{p=&s1;

cf(p);

}

//system("pause");

}

void  cf(struct date *p)

{

struct date s2;

s2.day=p->day;

s2.month=p->month;

s2.year=p->year;

switch(s2.month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

if(s2.day==31)

{

++s2.month;

s2.day=1;

}

else

{++s2.day;}

break;

case 12:

if(s2.day=31)

{

++s2.year;

s2.day=1;

s2.month=1;

}

else

{++s2.day;}

break;

case 4:

case 6:

case 9:

case 11:

if(s2.day==30)

{

++s2.month;

s2.day=1;

}

else

{++s2.day;}

break;

case 2:

if(((s2.year)%4==0)&&((s2.year)%100!=0)||((s2.year)%400==0))

{

if(s2.day==29)

{

++s2.month;

s2.day=1;

}

else

{++s2.day;}

}

else

{

if(s2.day==28)

{

++s2.month;

s2.day=1;

}

else

{++s2.day;}

}

break;

}

printf("输出新的日期:%d %d %d\n",s2.year,s2.month,s2.day);

}

//我测试了几个数据,应该没错

//没有添加输入数据是否合理的判断程序 例如2014 4 56,2014 2 29

//判断情况复杂,用switch

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值