填空题 C语言
题号 #2257379

请补充main()函数,该函数的功能是:把字符串strl中的非空格字符复制到字符串str2中。
例如,若str1="nice to meet you!",
则str2="nicetomeetyou!"。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在main()函数的横线上填人所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#define M 80
void main()
{
static char str1[M]="nice tO meet you!";
char str2[M];
int i=0,j=0;
system("CLS");
printf("\n****strl****\n");
puts(str1);
while(str1[i])
{
if(【1】)
str2[j++]=str1[i];
【2】 ;
}
printf("\n****str2****\n");
for(i=0;i<j;i++)
printf("%C",str2[i]);
}

进入在线模考

参考答案

暂无

答案解析

【1】str1[i]!=”【2】i+-
【解析】题目中要求把字符串str1中的非空格字符复制到字符串str2中,因此if语句的条件是判断str1中的字符不是空格,因此,【1】处填“str1[i]!=''”;由程序可知,变量i 为字符串str1中字符的下标,硷查字符串str1中的字符通过改变元素下标变量来实现,因此.【2】处填i++。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考