任务要求
设计程序,利用函数getCharacterCnt,实现求解出str所指字符串中指定字符的个数,并返回此值。 函数原型:int getCharacterCnt(char *str,char c)
输入要求
第一行输入字符串str(1<=len(str)<=1e6)
。 第二行输入一个字符c
,含义同任务要求。
输出要求
输出str所指字符串中指定字符的个数
//根据题目要求完成程序设计
#include <stdio.h>
/*
函数名称:getCharacterCnt
函数功能:获取指定字符的数量
*/
//设计函数getCharacterCnt
/*=====Begin=====*/
int getCharacterCnt(char* arr,char ch)
{
int i = 0;
int count = 0;
while(*(arr+i)!='\0')
{
if(*(arr+i)==ch)
{
count++;
}
i++;
}
return count;
}
/*======End======*/
/*
函数名称:solve
函数功能:程序入口,实现相应功能
*/
//设计函数solve
/*=====Begin=====*/
void solve()
{
int arr[1000000]={0};
gets(arr);
char ch = getchar();
printf("%d",getCharacterCnt(arr,ch));
}
/*======End======*/