Ok, I've figured it out. Finally. I made use of two different iterators instead of just the one like I tried to do - my output using the one was all palindromes.
Code:
//function declaration
string stringReverse(string arg)
{
char temp;
string word = arg;
int length = word.length() - 1;
for(int i = 0, b = length; i <= b; i++, b--){
temp = word[i];
word[i] = word[b];
word[b] = temp;
}
return word;
}
I'm new to the whole coding thing, so it's a little difficult for me to wrap my head around simple stuff like this. The idea is that I keep switching until the two counters meet or pass each other. is there any way I could improve upon this implementation?
I feel a little better now that I figured it out, but I still feel a little bit like a buffoon. Did you guys have similar troubles when you started out?