填空题
请补充main()函数,该函数的功能是:从键盘输入一组字符串,以“*”结束输入,并显示出这个字符串。
例如,输入ABCDEFG*,结果显示ABCDEFG。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在main()函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#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**display the string**/n");
while(j<i)
{
printf(
3);
j++;
}
}
【正确答案】
【答案解析】"%c",&str[i] str[i]!="*" "%c",str[j][解析] 由程序可知,从键盘输入的字符串存放在字符串变量str中。因此,第一处填“"%c",&str[i]”。题目中要求,字符串以“*”结束,语句while中的条件为字符串不结束的条件。因此,第二处填“str[i]!="*"”。printf用来格式化输出字符串str,变量j用来控制字符串的下标。因此,第三处填“"%c",str[j]”。