error C2109: 下标要求数组或指针类型 想不明白,求解~
#include<stdio.h>char*day[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Frid...
#include<stdio.h>
char * day[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int IsLeapYear(int year)
{
if(year<0)
{
printf("the year does not exit.");
return 0;
}
else
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;
}
}
int month_day(int year,int month)
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(IsLeapYear(year))
return 29;
else
return mon_day[month-1];
}
int SearchDay(int year,int month,int day)
{
int days=(year-1)*365+(int)(year-1)/400+(int)(year-1)/4-(int)(year-1)/100;
for(int i=1;i<month;i++)
days=days+month_day(year,month);
days=days+day;
int weekday=days%7;
return weekday;
}
void print(int year,int month,int day)
{
int n=SearchDay(year,month,day);
printf("%d-%d-%d is %s",year,month,day,day[n]); //error C2109: 下标要求数组或指针类型,n上给出的提示是“表达式必须包含指向对象的指针类型”
}
int main()
{
int year,month,day;
printf("input year month day\n");
scanf("%d %d %d",&year,&month,&day);
print(year,month,day);
return 0;
} 展开
char * day[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int IsLeapYear(int year)
{
if(year<0)
{
printf("the year does not exit.");
return 0;
}
else
{
if((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;
}
}
int month_day(int year,int month)
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(IsLeapYear(year))
return 29;
else
return mon_day[month-1];
}
int SearchDay(int year,int month,int day)
{
int days=(year-1)*365+(int)(year-1)/400+(int)(year-1)/4-(int)(year-1)/100;
for(int i=1;i<month;i++)
days=days+month_day(year,month);
days=days+day;
int weekday=days%7;
return weekday;
}
void print(int year,int month,int day)
{
int n=SearchDay(year,month,day);
printf("%d-%d-%d is %s",year,month,day,day[n]); //error C2109: 下标要求数组或指针类型,n上给出的提示是“表达式必须包含指向对象的指针类型”
}
int main()
{
int year,month,day;
printf("input year month day\n");
scanf("%d %d %d",&year,&month,&day);
print(year,month,day);
return 0;
} 展开
2个回答
展开全部
因为与你传入的变量名相同,在该函数里面,默认先识别内部变量名。所以报此错误
将char * dayo[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
指针数组全局变量名改一下就可以了
将char * dayo[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
指针数组全局变量名改一下就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询