请补充函数fun(),该函数的功能是:分类统计一个字符串中元音字母和其他字符的个数(不区分大小写)。 例如,输入aeiouAOUpqrt,结果为A∶2 E∶1 I∶1 O∶2 U∶2 Other∶4。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include<stdio.h> #include<conio.h> #define N 100 void fun(char *str,int bb[ ]) { char *p=str; int i=0; for(i=0;i<6;i++) 【1】 ; while(*p) {switch(*p){ case ’A’: case ’a’:bb[0]++;break; case ’E’: case ’e’:bb[1]++;break; case ’I’: case ’i’:bb[2]++;break; case ’O’: case ’o’:bb[3]++;break; case ’U’: case ’u’:bb[4]++;break; default: 【2】 ; } 【3】 } } main() { char str[N],ss[6]="AEIOU"; int i; int bb[6]; clrscr(); printf("Input a string:\n"); gets(str); printf("the string is:\n"); puts(str); fun(str,bb); for(i=0;i<5;i++) printf("\n%c:%d",ss[i],bb[i]); printf("\nother:%d",bb[i]); }
参考答案:[1] bb[i]=0 [2] bb[5]++ [3] p++;
解析: 填空1:数组bb[6]用来存放5个元音字母和其他字符的个数,在使用之前需要清零。填空2:数组元素bb[5]用来存放其他字符的个数,当指针p所指的字符不是元音字母时,则认为是其他字符,bb[5]加1。填空3:指针p指向字符串str,通过p自加1来移动指针,访问字符串中的所有字符。