填空题 C语言
题号 #2258353

请补充函数proc(),该函数的功能是:从“a”到“z”统计一个字符串中所有字母字符各自出现的次数,结果保存在数组buff中。注意:不区分大小写,不能使用字符串库函数。
例如,若输入:“A=abc+5*c”,则输出结果为:a=2 b=1 c=2,d以后所有字母字符出现的次数全为0。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<Conio.h>
#include<stdio.h>
#define M 100
void proc(char*str,int buffEl)
{
int i:
char*p=str;
for(i=0;i<26;i++)
【1】    ;
while(*p)
{
if(*p>='A '&&*p<='Z')
【2】  ;
if(*p>='a'&&*p<='2')
buff[*p-'a ']++;
【3】  ;
}
}
void main()
{
char str[M];
char a='a';
int buff[26],k;
system("CLS")。
printf("\nPlease enter a char string:");
scanf("%s",str);
printf("\n**The original string**\n");
puts(str);
proc(str,buff);
printf("n**The number of letter**\n");
for(k=0;k<26;k++)
{
if(k%5==0)
printf("\n");
printf("%c=%d",a+k,buff[k]):
}
printf("\n");
}

进入在线模考

参考答案

暂无

答案解析

【1】buff[i]=0【2】*p+=32【3】p++
【解析】数组alf中存放各个字母出现的次数,其各元素初始值为0,因此,【1】处填“alf[i]=0”;按题目中要求,不区分大小写,应将所有字母均转换为小写字母统一计算,因此,【2】处填“*P+=32”;要统计各个字母出现的次数,应检查字符串中的每一个字符,每一次循环结束后,指针P应向后移动一个位置,因此,【3】处填p++。

你可能感兴趣的试题

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