c程序查找字符出现次数

#include <stdio.h>
int main(){
    char str[100],ch,M,Empty;
	int i, frequency = 0;
	
    fgets(str, (sizeof str / sizeof str[0]), stdin);

	scanf("%c",&ch);
	scanf("%c",&M);
	scanf("%c",&Empty);

	for(i = 0; str[i] != '\0'; ++i)
	{
		if(ch == str[i])
			++frequency;
	}
	printf("字符 %c 在字符串中出现的次数为 %d\n", ch, frequency);
	return 0;
}

  

posted @ 2019-07-01 19:39  ToDarcy  阅读(589)  评论(0编辑  收藏  举报