国际税收协定基本内容:各位高手帮忙:用C语言编写一个程序,统计输入字符串中字符‘a’出现的次数。怎么编啊?

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/25 11:31:37
谢谢!

#include <string.h>

int strc()
{
char *s="good good study,day day up!";
char *p;
int sum=0;

p=strchr(s,'a');
while(p)
{
sum++;
*s=*p;
p=strchr(s,'a');
}
return sum;
}

#include <stdio.h>
int main(void)
{
char ch[100];
char* p=ch;
int nCount=0;
gets(p);
while (*p++)
if(*p=='a') nCount++;

printf("%d",nCount);
return 0;
}

main()
{char x;
int i=0;
printf("Please input:\n");
scanf("%c",&x);
for(;x!='.';)
{if(x=='a') i+=1;
scanf("%c",&x);}
printf("There is:%d\n",i);}
只要你输入的字符串以句号结尾就行了。