用c语言编写一个程序,用于接收一个字符串,并统计某字符在该 字符串中出现的次数

如题所述

第1个回答  2007-08-02
楼上,我帮你改一个小地方,就是最后1句

printf("\nThere are %d %c in string '%s'.\n", cnt, ch, str);

另while(str[i++]) ,改成while(str[++i])是不是更好一点
第2个回答  2007-08-02
#include<stdio.h>

#define MAX 100

void main()
{
char str[MAX], ch;
int i=0, cnt=0;

printf("Input a string:");
gets(str);
printf("Input a char:");
ch = getchar();
while(str[i++])
if(str[i-1]==ch)
cnt++;
printf("\nThere are %d '%c's in string '%s'.\n", cnt, ch, str);
}本回答被提问者和网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网