填空题
1. 请补充main()函数,该函数的功能是:从键盘输入一个字符串并保存在字符str1中,把字符串str1中下标为偶数的字符保存在字符串str2中并输出。
例如,当str1="computer"时,则str2="cmue"。
注意:部分源程序如下。
请勿改动函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。
试题程序: #include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define LEN 80
void main()
{
char str1[LEN],str2[LEN];
char*p1=str1,*p2=str2;
int i=0,j=0;
system("CLS");
printf("Enter the string: \n");
scanf(______);
printf("***the origial string***\n");
while(*(p1+j))
{
printf("______",*(p1+j));
j++;
}
for(i=0;i<j;i+=2)
*p2++=*(str1+i);
*p2='\0';
printf("\nThe new string is:% s\n", ______);
}
【正确答案】
1、"%s", str1
%c
str2
【答案解析】 由程序可知,目标字符串str2是原始字符串str1中下标为偶数的字符的组合。要得到目标字符串str2,首先要输入原始字符串str1,因此,第一空处填“"%s",str1”;第二空处是一个格式化的输出,str1为字符型,因此,第二空处填“%c”;最后是要输出目标字符串,而目标字符串放在str2中,因此,第三空处填“str2”。