会C的高手进来帮忙啊,偶正在考试,不会考啊。。。

来源:百度知道 编辑:UC知道 时间:2024/04/28 22:59:32
题目:编写一个程序,程序接受键盘输入的一个字符串,并找出该字符串中字符‘a’的出现次数。
要求:请用指针实现字符串操作,代码中不能出现数组的下标访问方式。
程序运行界面如下:
pleaose input the string:january
there are 2 characters for a

main()
{ char *s ,*p
int count=0;
scanf("%s",s);//接受键盘输入的字符串;
p=s;
while(p){
if(*p='a')
{ p++;
count++;
}//if
}//while
printf("%d",count);//a出现的次数;
}//main