问题 填空题

请补充main函数,该函数的功能是:把字符串str1中的非空格字符拷贝到字符串str2中。 例如,若sffl=“glad to see you!”, 则str2=“gladtoseeyou!”。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。 试题程序: #include<stdio.h> #define N 80 main() { static char strl [N] ="glad to see you!"; char str2 IN]; int i=0, j=0; clrscr (); printf("\n***** strl*****\n "); puts (str1); while (str1 [i] ) { if(【1】) str2 [J++] =strl [i]; 【2】; } printf("\n***** str2 *****\n "); for (i=0; i<j; i++) printf ("%c", str2 [i] ); }

答案

参考答案:[1] str1[i]!=’’ [2]i++

解析: 填空1:如果当前字符不为空格,则将它保存在字符串str2中。填空2:在while循环中,通过1忖取得字符串str1中当前字符的下一个字符,继续判断是否为空格。

选择题
单项选择题 B型题