|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <ctype.h>
#include <string.h>
char *s_gets(char *st, int n);
int lower(char *st);
int days(int year, int month, int day);
struct month{
char monthname[10];
char abbrev[4];
int days;
int num_month;
};
const struct month months[12] = {
{"January", "Jan", 31, 1},
{"February", "Feb", 28, 2},
{"March", "Mar", 31, 3},
{"April", "Apr", 30, 4},
{"May", "May", 31, 5},
{"June", "Jun", 30, 6},
{"July", "Jul", 31, 7},
{"August", "Aug", 31, 8},
{"September", "Sep", 30, 9},
{"October", "Oct", 31, 10},
{"November", "Nov", 30, 11},
{"December", "Dec", 31, 12}
};
int main(void)
{
char god[10];
int year, month, day;
printf("请输入年:");
while(scanf("%d", &year)==1)
{
printf("请输入月:");
if(scanf("%d", &month)==1)
;
else{
int i;
s_gets(god, 10);
for(i=0;i<12;i++)
{
if(strcmp(god, months[i].monthname)==0||strcmp(god, months[i].abbrev)==0)
{
month = months[i].num_month;
break;
}
}
}
printf("请输入日:");
scanf("%d", &day);
printf("您输入了%d年%d月%d日\n", year, month, day);
printf("一年直至这一天需要%d天\n", days(year,month,day));
printf("请输入年:");
}
printf("byb!\n");
return 0;
}
char *s_gets(char *st, int n)
{
char *fa;
char *find;
fa = fgets(st, n, stdin);
if(fa)
{
find = strchr(fa,'\n');
if(find)
*find = '\0';
else
while(getchar()!='\n')
continue;
}
return fa;
}
int days(int year, int month, int day)
{
int ch = 0;
int i ;
months[1].days = year % 4 == 0 ? 29 : 28;
for(i= 0;i<month-1;i++)
{
ch += months[i].days;
}
return ch +day;
}
红色那行,我觉得表达式没错误啊
怎么一直提醒报错,我晕了
求大佬帮助
你写的是const struct,不能改变
所以就报错了
去掉const可以: #include <stdio.h>
#include <ctype.h>
#include <string.h>
char *s_gets(char *st, int n);
int lower(char *st);
int days(int year, int month, int day);
struct month{
char monthname[10];
char abbrev[4];
int days;
int num_month;
};
struct month months[12] = {
{"January", "Jan", 31, 1},
{"February", "Feb", 28, 2},
{"March", "Mar", 31, 3},
{"April", "Apr", 30, 4},
{"May", "May", 31, 5},
{"June", "Jun", 30, 6},
{"July", "Jul", 31, 7},
{"August", "Aug", 31, 8},
{"September", "Sep", 30, 9},
{"October", "Oct", 31, 10},
{"November", "Nov", 30, 11},
{"December", "Dec", 31, 12}
};
int main(void)
{
char god[10];
int year, month, day;
printf("请输入年:");
while(scanf("%d", &year)==1)
{
printf("请输入月:");
if(scanf("%d", &month)==1)
;
else{
int i;
s_gets(god, 10);
for(i=0;i<12;i++)
{
if(strcmp(god, months[i].monthname)==0||strcmp(god, months[i].abbrev)==0)
{
month = months[i].num_month;
break;
}
}
}
printf("请输入日:");
scanf("%d", &day);
printf("您输入了%d年%d月%d日\n", year, month, day);
printf("一年直至这一天需要%d天\n", days(year,month,day));
printf("请输入年:");
}
printf("byb!\n");
return 0;
}
char *s_gets(char *st, int n)
{
char *fa;
char *find;
fa = fgets(st, n, stdin);
if(fa)
{
find = strchr(fa,'\n');
if(find)
*find = '\0';
else
while(getchar()!='\n')
continue;
}
return fa;
}
int days(int year, int month, int day)
{
int ch = 0;
int i;
months[1].days = (year % 4 == 0 ? 29 : 28);
for(i= 0;i<month-1;i++)
{
ch += months[i].days;
}
return ch + day;
}
|
|