填空题
C语言
题号 #2255728
请补充main()函数,该函数的功能是:从键盘输入一字符串并保存在字符str1中,把字符串str1中下标为偶的字符保存在字符串str2中并输出。例如,当str1="cc puter",则str2=”crnue”。
注意:部分源程序给出如下。
请勿改动函数中的任何内容,仅在横线上填入所编的若干表达式或语句。
试题程序:
#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");
print{("Enter the string:\n");
scanf(【1】);
print{("***the origial string***\n");
while(*(p1+j))
{
printf("【2】",*(p1+j));
j++;
}
for(i=0;i<j;i+=2)
*p2++=*(strl+i);
*p2='\0';
print{("\nThe new string is:%s\n",【3】);
}
参考答案
暂无
答案解析
【1】"%s",str1【2】%c【3】str2
【解析】由程序可知,目标字符串str2是原始字符串str1 中下标为偶数的字符的组合。要得到目标字符串str2,首先要输入原始字符串str1,因此【1】填“"%s",str1”;【2】处是一个格式化的输出,str1为字符型,因此【2】填“%c”;最后是要输出目标字符串,而目标字符串放在str2中,因此【3】填“str2”。