填空题
请补充main函数,该函数的功能是:从键盘输入一个字符串并保存在字符str1中,把字符串str1中下标为偶数的字符保存在字符串str2中并输出。例如,当str1=“cdefghij”,则 str2=“cegi”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define LEN 80
main()
{
char str1[LEN],str2 [LEN];
char *p1=str1,*p2=str2;
int i=0,j=0;
clrscr();
printf("Enter the string:/n");
scanf({{U}} 【1】 {{/U}});
printf("***the origial string***/n");
while(*(p1+j))
{
printf("{{U}} 【2】 {{/U}}",*(p1+j));
j++;
}
for(i=0;i<j;i+=2)
*p2++=*(str1+i);
*p2='/0';
printf("/nThe new string is:%s/n",{{U}} 【3】 {{/U}});
}
【正确答案】
1、【1】"%s",str1 【2】%c 【3】str2
【答案解析】[解析] 填空1:本题考查对标准输入函数scanf()的调用格式,当输入字符串时,格式控制字符串为“%s”,题目要求输入的字符串保存在str1中,所以地址表列应为字符串的首地址,即为str1。填空2:本题考查对标准输出函数printf()的调用格式,当输出为字符型变量时,格式控制字符串为“%c”。填空3:题目要求将str1中下标为偶数的字符保存在字符串str2中并输出,所以ptintf()函数的输出表列是str2。