计算机二级C语言上机考试填空题及答案2

全国等级考试资料网 2022-08-19 12:20:51 274
填空题
请补充main函数,该函数的功能是:把字符串str1中的非空格字符拷贝到字符串str2中.
例如,若str1=”nice to meet you!”,则str2=”nicetomeetyou!”
仅在横线上填入所编写的若干表达式或语句,勿改动函数中的其他任何内容.
#include
#define N 80
main()
{
static char str1[N] = "nice to meet you!";
char str2[N];
int i = 0, j = 0;
printf(" ****** str1 ****** ");
puts(str1);
while (str1[i])
{
if (___1___)
str2[j++] = str1[i];
___2___;
}
printf(" ****** str2 ****** ");
for (i=0; iprintf("%c", str2[i]);
}
参考答案:
第一题:
第1处填空str1[i]!=’ ’或’ ’!= str1[i]
第2处填空i++或++i或i+=1或i=i+1 相关资料

相关阅读