#include
int main(int argc, char const *argv[])
{
char buf[256] = {0};
char *p = NULL;
int num = 0;
scanf("%s",buf);
p = buf;
while(*p)
{
if (*p == 'a')
{
*p = 'b';
num ++;
}
p ++;
}
printf("the a num:%d string:%s\n",num,buf);
return 0;
}
#include
int replace(char string[]){
int count = 0;
char* p = string;
while(*p){
if(*p == 'a'){
count ++;
*p = 'b';
}
p ++;
}
return count;
}
int main(){
char string[1024];
printf("请输入字符串:");
gets(string);
printf("a的个数:%d\n替换后的字符串是:%s\n", replace(string), string);
return 0;
}