给定程序中,函数fun的功能是:计算出形参s所指字符串中包含的单词个数,作为函数值返回。为便于统计,规定各单词之间用空格隔开。 例如,形参s所指的字符串为:This is a C languageprogram.,函数的返回值为6。 请在程

admin2017-02-27  49

问题 给定程序中,函数fun的功能是:计算出形参s所指字符串中包含的单词个数,作为函数值返回。为便于统计,规定各单词之间用空格隔开。
    例如,形参s所指的字符串为:This is a C languageprogram.,函数的返回值为6。
    请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
    注意:源程序存放在考生文件夹下的BLANK1.C中。
    不得增行或删行,也不得更改程序的结构!
#include  
int  fun (char  *s)
{ int n=0,flag=0;
      ____1____  ;  flag=1; }
    ____3____;
  }
  return n;
main ()
{  char str[81]; int n:
   printf ("\nEnter a line text:\n") ;
gets (str) ;
   n=fun (str) ;
printf("\nThere are %d words in
this text.\n\n",n) ;
}

选项

答案(1)n++ (2)0 (3)s++

解析 函数fun的功能是计算出形参s所指字符串中包含的单词个数。
第一空:“if(*s!=’’&&nag==0)”说明找到空格了,单词的数量应加1,故第一空处应为“n++”。
第二空:“if(*s!=’’&&flag==0)”和“if(*s==’’)flag=____2____; ”在flag为0的情况下,n才加1,因此第二空处是将flag置0,即第二空处应为“0”。
第三空:“while(*s!=’\0’)”循环的终止条件是s达到结尾,因此在循环体内s应该不断往字符串尾移动,即第三空为“S++”。
转载请注明原文地址:https://kaotiyun.com/show/lrID777K
0

相关试题推荐
最新回复(0)