这是Kochan所编的<<Programming in C>>中的一个例题,但运行时为什么回出现如题状况呢?我所采用的运行平台为Turbo C for Windows.换用其它运行平台时依然如此.我的文件命名应该没问题的啊,文件名为dateUpdate.C
#include <stdio.h>
#include <stdbool.h>
struct date
{
int month;
int day;
int year;
};
int main(void)
{
struct date today,tomorrow;
int numberOfDays(struct date d);
printf ("please type in today's date(mm dd yyyy):");
scanf ("%i%i%i",&today.month,&today.day,&today.year);
if (today.day != numberOfDays(today))
{
tomorrow.day=today.day+1;
tomorrow.month=today.month;
tomorrow.year=today.year;
}
else if (today.month == 12)
{
tomorrow.day=1;
tomorrow.month=1;
tomorrow.year=today.year + 1;
}
else
{
tomorrow.day=1;
tomorrow.month=today.month + 1;
tomorrow.year=today.year;
}
printf ("tomorrow's date is %i/%i/%.2i.\n",tomorrow.month,tomorrow.day,tomorrow.year % 100);
return 0;
}
/*判断是否为闰年的函数*/
bool isLeapYear(struct date d)
{
bool LeapYearFlag;
if (d.year % 4 ==0 && d.year % 100 != 0 || d.year % 400 == 0)
LeapYearFlag = true;
else
LeapYearFlag = false;
return LeapYearFlag;
}
/*查找一个月中日期数的函数*/
int numberOfDays (struct date d)
{
int days;
bool isLeapYear (struct date d);
const int daysPerMonth[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
if (isLeapYear(d) == true && d.month == 2)
days = 29;
else
days = daysPerMonth[d.month - 1];
return days;
}