以下是一段驶入一个日期,然后输出下一天的日期的代码,但是这段代码我输入了日期之后程序什么也不输出,(注:把scanf改成scanf_s是因为visual studio一直说我返回值被忽略),至于为什么不输出,我找AI看了也没看明白,哪位大佬能不吝赐教一下,感激不尽
#pragma warning(disable:4996)
#include <stdio.h>
typedef struct date {//一个包含年月日的结构体
int year;
int month;
int day;
}date;
int isleap(date d) {//判断闰年函数
if ((d.year % 4 == 0 && d.year % 100 != 0) || (d.year % 400 == 0)) {
return 1;
}
else {
return 0;
}
}
int day1(date d) {
const int days[13] = { 0,31,28,31,30,31,30,31,30,31,30,31,30 };
if (d.month == 2 && d.day == 29) {
if (isleap(d)) {
printf("next day is %d/%d/%d", d.year, d.month + 1, 1);
}
else {
printf("wrong");
}
}
else if (d.month == 2 && d.day == 28) {
if (isleap(d)) {
printf("next day is %d/%d/%d", d.year, d.month, d.day + 1);
}
else {
printf("next day is %d/%d/%d", d.year, d.month + 1, 1);
}
}
else if (d.day == 30) {
if (days[d.month] == 30) {
if (d.month == 12) {
printf("next day is %d/%d/%d", d.year + 1, 1, 1);
}
else {
printf("next day is %d/%d/%d", d.year, d.month + 1, 1);
}
}
else if (d.day == 31) {
if (days[d.month] == 31) {
printf("next day is %d/%d/%d", d.year, d.month + 1, 1);
}
else {
printf("wrong");
}
}
else {
printf("next day is %d/%d/%d", d.year, d.month, d.day + 1);
}
}
return 1;
}
int main() {
date d;
scanf_s("%d %d %d", &d.year, &d.month, &d.day);
day1(d);
return 0;
}
标签:31,printf,month,else,year,新手,C语言,day,疑问
From: https://blog.csdn.net/2401_87318028/article/details/144117459