c程序查找字符出现次数

#include 
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;
}

  

转载于:https://www.cnblogs.com/todarcy/p/11116290.html

你可能感兴趣的:(c程序查找字符出现次数)