String issue

So I'm trying to check part of a string against another part of the same string, but it doesn't seem to be a use of brackets for the location in the string like I was led to believe.
I just need some help with the location in the string.

1
2
3
4
5
6
7
8
9
10
bool PT(int& loop, int length, string ppd)
{
	int endDIS = length - loop;

	if (ppd[endDIS] == ppd[loop])
	{
		loop++;
		return PT(loop, length, ppd);
	}
}
Where is this function returning a bool?

Do you realize that ppd[endDIS] is a single character (as long as endDIS is a valid index value) not a string?

I want ppd[endDIS] to be a single character, just like ppd[loop], but when I trace the program through, even when using AA, the function always returns false, and never goes into the if statement shown

the function is returning right here

bool test = false;
test = PT(loop, length, ppd);
You have forgot to return something from the function when the if condition is false.
is this any better

if (ppd[endDIS] == ppd[loop])
{
loop++;
return PT(loop, length, ppd);
}
else if (loop == length)
{
return true;
}
else
return false;
}
Last edited on
int endDIS = length - loop;

It looks like you're trying to test if the string is a palindrome. In the above line, when loop is 0, endDIS will be length. So, you'll be comparing the first letter of the string to the nul character which ends it.
Thanks, that got it. I appreciate the help guys!
Topic archived. No new replies allowed.