请补充main函数,该函数的功能是:把字符串str1中的非空格字符拷贝到字符串str2中。 例如,若sffl=“glad to see you!”, 则str2=“gladtoseeyou!”。 注意:部分源程序给出如下。 请勿改动

admin2010-09-14  22

问题 请补充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 )
      {
           if(【  】)
               str2 [J++] =strl ;
【  】;
      }
      printf("\n***** str2 *****\n ");
      for (i=0; i<j; i++)
          printf ("%c", str2 );
   }

选项

答案str1[i]!=’’ i++

解析 第一空:如果当前字符不为空格,则将它保存在字符串str2中。第二空:在while循环中,通过1忖取得字符串str1中当前字符的下一个字符,继续判断是否为空格。
转载请注明原文地址:https://kaotiyun.com/show/uWID777K
0

最新回复(0)