填空题
C语言
题号 #2255319
请补充main()函数,该函数的功能是:从键盘输入一组字符串,以“*”结束输入,并显示出这个字符串。
例如,输入ABCDEFG*,结果显示ABCDEFG。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在main()函数的横线上填人所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.1>
#define M 80
void main()
{
int i=-1,j=0;
char str[M];
system("CLS");
printf("\n Input a string\n");
do
{
i++;
scanf(【1】);
}
while(【2】);
printf("\n**llisplay the string**\n");
while(j<i)
{
printf(【3】);
j++;
}
}
参考答案
暂无
答案解析
【1】"%c",&str[i]【Z】slr[i]!='*'【3】"%c",str [j]
【解析】由程序可知,从键盘输入的字符串存放在字符串变量str中。因此,【l】处填"%c",&str[i]”。题目中要求,字符串以“*”结束,语句while中的条件为字符串不结束的条件。因此,【2】处填“str[i]!='*'”。printf用来格式化输出字符串str,变量j用来控制字符串的下标。因此,【3】处填“"%C",str[j]”。