为方便广大考生更好的复习2013年计算机二级C语言考试,查找考试辅导习题,考试站网校特提供了C语言上机预测题(填空题、改错题、编程题),更多模拟无纸化考试“计算机二级C语言模拟题”,供考生学习。
填空题
Str是全部由小写字母字符和空格字符组成的字符串,由num传入字符串的长度,请补充fun函数,该函数的功能是:统计字符串str中的单词数,结果由变量num传回。给个单词之间有空格隔开,并且字符串str开始不存在空格。
例如,str=”how are you”,结果为:num=3.
注意:部分源程序给出如下
请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
#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