遇到一个问题 编译器一直编译不过去 好像内存冲突
#include<iostream>#define D 50
using namespace std;
int replace(char *str, char c1, char c2); //把字符串里char c1的字符改成char c2
int main()
{
char *arr="a5a5a5a5a5a5a5a5a5a";
int z;
z = replace(arr, 'a', 'c');
cout << "字符串:" << arr << endl;
cout << "有" << z << "个字符a转换成c." << endl;
system("pause");
return 0;
}
int replace(char *str, char c1, char c2)
{
int i = 0;
char *st;
st = str;
while (st!='\0')
{
if (*st == c1)
{
i++;
*st = c2;
}
st++;
}
return i;
}
大神来看看怎么回事?