看看这个c语言程序哪错了,为什么结果总是首字母而不是整个单词呢
答案:5 悬赏:20 手机版
解决时间 2021-03-25 03:02
- 提问者网友:城市野鹿
- 2021-03-24 16:10
看看这个c语言程序哪错了,为什么结果总是首字母而不是整个单词呢
最佳答案
- 五星知识达人网友:春色三分
- 2021-03-24 16:31
帮你改好了,有两个地方要改,你仔细看看。
int main()
{
char *a[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int i,j;
printf("输入一个1~7的整数:
");
scanf("%d",&j);
i=j-1;
printf("%s
",a[i]);
return 0;
}
int main()
{
char *a[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int i,j;
printf("输入一个1~7的整数:
");
scanf("%d",&j);
i=j-1;
printf("%s
",a[i]);
return 0;
}
全部回答
- 1楼网友:话散在刀尖上
- 2021-03-24 18:07
printf("%s\n",a[i]);
- 2楼网友:舊物识亽
- 2021-03-24 17:42
你这里字符串数组相当于二维数组,每一个字符串相当于一个一维数组。用一维下标表示时,a[i]是每个一维元素,即一维数组的地址,也即每个字符串的首字母的地址,*a[i]当然就是每个字符串的首地址了。
- 3楼网友:未来江山和你
- 2021-03-24 17:32
你把printf里边的%c改为%s试试,%c本身就输出一个字符,%s才是输出字符串的格式控制符。
- 4楼网友:白昼之月
- 2021-03-24 16:49
#include
int main()
{
char *a[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int i,j;
printf("输入一个1~7的整数:\n");
scanf("%d",&j);
i=j-1;
printf("%s\n",*(a+i));
return 0;
}
int main()
{
char *a[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int i,j;
printf("输入一个1~7的整数:\n");
scanf("%d",&j);
i=j-1;
printf("%s\n",*(a+i));
return 0;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯