在线等!!!!!编程实现:从键盘上输入一个字符串和一个字符,统计该字符在字符串中出现的次数 !急!

追加悬赏

#include <stdio.h>
#include <string.h>
#define N 10

void main()
{
char ch;
char str[N] = {0};
int i = 0, j = 0;

printf("请输入字符串 : ");
gets(str);
printf("请输入要查找的字符: ");
scanf("%c", &ch);

for (i; i < strlen(str); i++)
{
if (str[i] == ch)
{
j++;
}
}

printf("字符%c出现的个数为 : %d \n ",ch, j);

}

懂不?
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-11-17
这是我做的一个类似的你改改吧
#include <stdio.h>
main(){
char str[50]="";
int i ,n=0;
gets(str);
for(i=0;str[i];i++)
if(str[i]='I') n++;
printf("\nI出现的次数为%d次",n);}
相似回答