填空题 C语言
题号 #2257008

请补充函数proc(),该函数的功能是:返回字符数组中指定字符的个数,指定字符从键盘输入。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填人所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#define M 80
int proc(char str[],char ch)
{
int i=0,n=0:
while(【1】)
{
if(【2】)
n++;
i++;
}
【3】 ;
}
void main()
{
int n;
char str[M],ch;
system("CLS"):
printf("\nInput a string:\n");
gets(str);
printf("\nlnput a chractor:\n");
scanf("%C",&ch);
n=proe(str,ch)。
printf("\nnumber of%c:%d",ch,n);
}

进入在线模考

参考答案

暂无

答案解析

【1】str[i]!='\0 '【2】str[]==ch【3】return n
【解析】要返回字符数组中指定字符的个数,需要将字
符串中的每一个字符与指定字符相比较,直到字符串结束,因此,【1】处填“str[i]!='\0'”;每找到一个与指定字符相同的字符,计数器加1,因此,【2】处填“str[i]==ch”;最后,将相目同的字符个数返回到主函数中,因此,【3】处填“return n”。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考