标题:结构{复合字面量问题}
取消只看楼主
huangfengchu
Rank: 1
等 级:新手上路
威 望:2
帖 子:274
专家分:0
注 册:2007-5-22
 问题点数:0 回复次数:2 
结构{复合字面量问题}

这是一个计算下一天日期程序。问题出现在函数部分复合字面量地方出现语法错误,找了很久,没发现解决办法,请帮我指出一下。
struct date
{
int month;
int year;
int day;
};
struct date update(struct date today)
{
struct date tomorrow;
const int dayspermonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int days;
if(today.year%4==0&&today.year%100!=0||today.year%400==0&&today.month==2)
days=29;
else
days=dayspermonth[today.month-1];
if(today.day!=days)
tomorrow=(struct date){today.month,today.day+1,today.year};

else if (today.month==12)
tomorrow=(struct date){1,1,today.year+1};

else
tomorrow=(struct date){today.monnth+1,1,today.year};
return tomorrow;
}
int main(void)
{
struct date thisdate,nextdate;
struct date update(struct date today);
printf("Input date's date (mm dd yyyy)");
scanf("%i:%i:%i",&thisdate.month,&thisdate.day,&thisdate.year);
nextdate=update(thisdate);
printf("%i:%i:%i",nextdate.month,nextdate.day,nextdate.year);
return 0;
}

搜索更多相关主题的帖子: 字面量 int today 结构 year 
2007-06-11 01:06
huangfengchu
Rank: 1
等 级:新手上路
威 望:2
帖 子:274
专家分:0
注 册:2007-5-22
得分:0 
楼上,先谢你指出的这个month错误,但是还是运行不了。我用的的WIN-TC,不知道是不是编译器问题,你能运行吗?

深山苦学C语言,终年不见外面世界。
2007-06-11 18:05
huangfengchu
Rank: 1
等 级:新手上路
威 望:2
帖 子:274
专家分:0
注 册:2007-5-22
得分:0 

括号看见的,那个都没问题。可有可无,只是可读性好点,我用WIN-TC就报错结构中表达式错误。就那三表达式错误,我想应该是编译器问题了,谢谢你。


深山苦学C语言,终年不见外面世界。
2007-06-11 18:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-146450-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.310537 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved