问答题
给定程序中,函数fun的功能是:计算出形参s所指字符串中包含的单词个数,作为函数值返回。为便于统计,规定各单词之间用空格隔开。
例如,形参s所指的字符串为:This is a C language program.,函数的返回值为6。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序在文件BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
int fun(char*S)
{ int n=0,flag=0;
while(*S!='\0')
{if(*S!=''&&flag==0){
/*********found*********/
【1】
;flag=1;)
/*********found*********/
if(*S=='')flag=
【2】
;
/*********found*********/
【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);
}