满意答案
Sicevoise
2013.11.12
采纳率:53% 等级:12
已帮助:13187人
调用系统的mktime(),获取 time_t 型日期时间,增 24.0 * 3600.0秒 就是下一天。
不检查输入数据。
#include
#include
#include
void NextDate(int *month, int *day, int *year){
time_t now,next;
struct tm *target;
time ( &now );
target=localtime(&now);
target->tm_year = *year - 1900;
target->tm_mon= *month -1;
target->tm_mday= *day;
now = mktime(target);
now = now + 24.0 * 3600.0;
target=localtime(&now);
*month = target->tm_mon+1;
*day = target->tm_mday;
*year = target->tm_year + 1900;
}
main(){
int m,d,y;
printf("please input month day year\n");
printf("1<=month<=12, 1<=day<=31, 1920 <=year<=2050\n");
scanf("%d %d %d",&m,&d,&y);
NextDate(&m,&d,&y);
printf("next date is %d %d %d\n",m,d,y);
}
// 试运行:
please input month day year
2 28 2013
next date is 3 1 2013
// 试运行:
please input month day year
2 28 2012
next date is 2 29 2012
112分享举报