owolablo said:
Can anybody please tell me how to change the individual elements of a
char variable. I need to parse through the string, check for a
particular character and change it to something else if it is found.
A char variable doesn't have "individual elements", unless perhaps you
could consider the individual bits that make up its representation to
be "individual elements", but I don't think that is your question.
char c = 'c';
A char variable is just that, a single character.
I think your question is, how do I replace all occurrances of a
particular char with a different char in a string. If that is your
question, then:
1. Stop using null-terminated arrays of char to represent strings in
C++. Use std::string. It makes your life (including this sort of
question) so much easier.
2. The standard library provides an algorithm, std::replace, that does
what you need.
Gavin Deane