填空题 1.  请补充main()函数,该函数的功能是:把字符串str1中的非空格字符复制到字符串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****str1****<n");
    puts(str1);
    while(str1[i])
    {
    if (______)
    str2[j++]=strl[i];
    ______;
    }
    printf("<n****str2****<n");
    for(i=0;i<j;i++)
    printf("%c",str2[i]);
    }
  • 1、
【正确答案】 1、str1[i]!==''
i++    
【答案解析】 题目中要求把字符串str1中的非空格字符复制到字符串str2中,因此if语句的条件是判断str1中的字符不是空格,因此,第一空填“str1[i]!=””。由程序可知,变量i为字符串str1中字符的下标,检查字符串str1中的字符,通过改变元素下标变量来实现,因此,第二空填“i++”。