Converting one character into another

Hello Guys

I want to convert one character into another
e.g.
array[10] has 10 characters like abcdefghij

now I want to change all the a's in array into z's
how can I do that

here's an example code
1
2
3
4
5
6
7
8
9
10
  #include <iostream>
using namespace std;

int main() {
	char arr[10],s[10],a="s",b="y";
	cin>>arr[1];
	if(arr[1]==a) s[1]=b;
	cout<<s[1];
	return 0;
}

Thanks
Loop over all characters in your array check and replace them
1
2
for(int i /*...*/)
    if(arr[i] == a) arr[i] = b;
or use std::replace
http://coliru.stacked-crooked.com/a/e0065bf141ae559f
Last edited on
Topic archived. No new replies allowed.