2011年计算机二级C语言上机操作题及答案(35)

2014-11-21 23:00:16 · 作者: · 浏览: 19

第35套


填空题


Str是全部由小写字母字符和空格字符组成的字符串,由num传入字符串的长度,请补充fun函数,该函数的功能是:统计字符串str中的单词数,结果由变量num传回。给个单词之间有空格隔开,并且字符串str开始不存在空格。


例如,str=”how are you”,结果为:num=3.


注意:部分源程序给出如下


请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句。


试题程序:


#include


#define N 80


void fun(char *s, int *num)


{


int i, n = 0;


for (i=0; ___1___; i++)


if (s[i]>='a' && s[i]<='z' && s[i+1]==' ' || s[i+1]=='\0')


___2___;


___3___;


}


main()


{


char str[N];


int num = 0;


printf("Enter a string :\n");


gets(str);


while (str[num])


num++;


fun(str, &num);


printf("The number of word is : %d\n\n", num);


}


第1处填空:i<*num或*num>i


第2处填空:n++或++n或n+=1或n=n+1


第3处填空:*num=n


编辑特别推荐: