填空题 C语言
题号 #2256742

str是全部由小写字母字符和空格字符组成的字符串,由hum传人字符串的长度。请补充函数proc(),该函数的功能是:统计字符串str中的单词个数,结果由变量num传回。每个单词之间都由空格隔开,并且字符串str开始不存在空格。
例如,str="how do you do",结果为:num=4。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填人所编写的若干表达式或语句。
试题程序:
#include<stdi0.h>
#define M 80
void proc(char*str,int*num)
{
int i,n=0:
for(i=0;【l】 ;i++)
{
if(str[i]>='a'&&str[i]<='2'&&(str[i+1]

 =='' || str[i +1]=='\0 '))

      【2】 ;

   }

   【3】 ;

}

void main()

{

   char str[M];

   int num=0:

   printf("Enter a st ring:\n");

   gets(str);

   while(str[num])

   num++:

   proc(str,&.num):

   printf("The number of word is:

   %d\n\n",hum);

}

进入在线模考

参考答案

暂无

答案解析

【1】i<*num【2】n++ 【3】*num=n
【解析】由主函数的proc()函数调用可知,变量Flum中存放的是字符串str的字符个数,因此,【1】处填“i<* num”;由函数proc()可知,变量n中存放字符串str中的字符个数,每检测到一个空格或字符串结束,单词数加1,因此’【2】处填“n++”;字符串str中的单词数要由形参num 传递回主函数,因此,【3】处填“*num=n”。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考