下面程序说让用户任意输入英文的星期几,在查找星期表后输出其对应的数字。此程序有错误,是什么?为什么
#include<stdio.h>main(){inti,pos=0;intflag=0;charx[10];charday[7][4]={"sun","mon","tu...
#include <stdio.h>
main()
{
int i, pos=0;
int flag=0;
char x[10];
char day[7][4]={"sun","mon","tue","wed","thu","fri","sat"};
printf("Please enter a string: ");
scanf("%s", &x);
for (i=0; i<7 && !flag; i++)
{
if (x == day[i])
{
pos = i;
flag=1;
}
}
if (flag=1)
{
printf("%s is %d\n", x, pos);
}
else
{
printf("No found!");
}
} 展开
main()
{
int i, pos=0;
int flag=0;
char x[10];
char day[7][4]={"sun","mon","tue","wed","thu","fri","sat"};
printf("Please enter a string: ");
scanf("%s", &x);
for (i=0; i<7 && !flag; i++)
{
if (x == day[i])
{
pos = i;
flag=1;
}
}
if (flag=1)
{
printf("%s is %d\n", x, pos);
}
else
{
printf("No found!");
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询