Debug Problem? PLEASE HELP

May 1, 2012 at 7:48pm
ddd
Last edited on May 3, 2012 at 3:26am
May 1, 2012 at 8:52pm
I think the problem is with the while loop?
May 1, 2012 at 9:41pm
I've been working on it a lot, haven't solved the problem. I've identified it's wi
Last edited on May 3, 2012 at 3:26am
May 2, 2012 at 3:18am
bump
May 2, 2012 at 9:01am
The problem is probably reverseMessage(message);. I don't know what may cause an error...
May 2, 2012 at 7:52pm
:( anyone else have any idea?
May 2, 2012 at 7:57pm
Remember, the last valid index in a string = length - 1.

Same with all STL containers.

1
2
3
	string example = "Hello!";
	int len = example.length();
	char check = example[len - 1];


check = '!'
Last edited on May 2, 2012 at 8:18pm
May 2, 2012 at 8:02pm
PS trivia?

It's more usual to align else ifs with the if they're an else of, esp when they all test the same variable in a similar way. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
void exchangeCHAR(char msgCHAR)
{
	if(msgCHAR == 'A' || msgCHAR == 'a')
		msgCHAR = '~';
	else if(msgCHAR == 'e' || msgCHAR == 'E')
		msgCHAR = '|';
	else if(msgCHAR == 'i' || msgCHAR == 'I')
		msgCHAR = '\'';
	else if(msgCHAR == 'o' || msgCHAR == 'O')
		msgCHAR = '{';
	else if(msgCHAR == 'u' || msgCHAR == 'U')
		msgCHAR = ']';
}


This makes it easier to see all the tests are close relatives of each other.
Last edited on May 2, 2012 at 8:05pm
May 2, 2012 at 11:32pm
Remember, the last valid index in a string = length - 1.

Same with all STL containers.


Thanks for the example. I think I understand; so exchangeCHAR should be exchangeCHAR(message[msgLength-1]), but I still get the error!

also, thanks for your tip. I'll make sure to follow that.
May 2, 2012 at 11:37pm
Your loop at line 70 definitely needs to change, the other posters in this thread gave some good advice there, however your function exchangeCHAR needs a bit of work also. The way it stands at the moment, it won't have any effect. When you pass a variable to a function by value, the function makes a local copy of that variable. That is what you are changing in your function. That means it won't have any effect on the original char variable. You will need to use a pointer or a reference to a char to make it work. I would recommend using a reference, since you would only need to change "char msgChar" to "char& msgChar"
May 3, 2012 at 12:00am
Your loop at line 70 definitely needs to change, the other posters in this thread gave some good advice there, however your function exchangeCHAR needs a bit of work also. The way it stands at the moment, it won't have any effect. When you pass a variable to a function by value, the function makes a local copy of that variable. That is what you are changing in your function. That means it won't have any effect on the original char variable. You will need to use a pointer or a reference to a char to make it work. I would recommend using a reference, since you would only need to change "char msgChar" to "char& msgChar"


Thanks so much for the tip! However, even after making the change you suggested as well as the change that the previous poster suggested I still get an error! I'm sorry for being a bother, but I just can't understand what is wrong.
Topic archived. No new replies allowed.