问题 填空题

[说明] 从键盘输入一个字符ch,输出该字符在文本文件input.txt 的每一行中出现的次数。(必须调用函数鳋统计ch的出现次数,函数ff (str,ch)的功能是统计并返回字符ch在字符串str 中出现的次数。)。
例如:如果文件input. txt 中存放了下列数据:
every
121
I am a student
运行程序,并输入e后,输出:
2
0
1
int ff( char * str, char ch)
int count =0;
while ( (1) )
if( *str= =ch) count++;
str ++;

return count;

# include < stdio. h >
# include < stdlib. h >
void main( )
char ch, c, s [80];
int k;
FILE *fp;
if( (2) )
printf( “打不开文件!n”); return;

ch = getchar( );
k=0;
while( ! feof(fp) )
c = fgete(fp);
if (3)
s[k++ ] =c;
else
s[k]= ";
printf ( "%dn" ,ff(s, ch) );
k=0;


(4)
printf( "% dn", ff( s, ch ) );

答案

参考答案:( *str)
(fp = fopen( :input. txt" ,"r" ) ) = = NULL
(c! =’n’)
s[k] =’’;

选择题
单项选择题 B型题