c程序查找字符出现次数

Posted todarcy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;

  

以上是关于c程序查找字符出现次数的主要内容,如果未能解决你的问题,请参考以下文章