閱讀以下說明和 C 代碼,填充代碼中的空缺,將解答填入答題紙的對應欄內。
【說明 1】
下面的函數 countChar(char *text)統(tǒng)計字行串 text 中不同的英文字母數和每個英文字母出現的次數(英文字母不區(qū)分大小寫)。
【c代碼1】
int countChar( char *text )
{
int i,sum = 0; /* sum 保存不同的英文字母數*/
char *ptr;
int c[26] = {0}; /*數組c保存每個英文字母出現的次數*/
/*c[0]記錄字母A或a的次數,c[1] 記錄字母B或b的次數,依此類推*/
ptr = (1) ;/*ptr初始時指向字符串的首字符*/
while (*ptr) {
if ( isupper(*ptr) )
c[*ptr - 'A']++;
e1se
if ( islower(*ptr) )
c[*ptr - 'a'] ++;
(2) ; /*指向下一個字符*/
}
for(i=0;i<26;i++)
if (3) sum++;
return sum;
}
【說明2】
將下面C代碼2中的空缺補全后運行,使其產生以下輸出。
f2:f2:f2:2
f3:f3: 1
【C代碼2】
*include <stdio.h>
int f1 (int (*f) (int)) ;
int f2 (int) ;
int f3 (int) ;
int main ()
{
printf("%d\n" ,f1( (4) ));
printf("%d\n" ,f1( (5) ));
return 0;
}
int f1 ( int (*f) (int) )
{
int n = 0;
/*通過函數指針實現函數調用,以返回值作為循環(huán)條件*/
while ( (6) ) n++;
return n;
}
int f2(int n)
{
printf("f2: ");
return n*n-4;
}
int f3 (int n)
{
printf("f3: ");
return n-1;
}