tags:

views:

126

answers:

4

for (int i = len-2; index>= 0; index --)

+4  A: 

You are using two variables: i and index, maybe this is causing trouble to you?

Konamiman
+4  A: 

Without any real context I would venture that int i should be replaced with int index.

Chris Bunch
Also, unless you want to start at the *second to* last character, use (int index = len-1 ...
Chris Nava
A: 

You are looping through the string backwards? (I suppose that was your intention)

You are also not starting with the very last character in the string, you are starting with the second last (len-2).

theycallmemorty
He might be leaving a newline character out of the loop. -1 for 0-based string length, -1 for the newline character (Cr, Lf).
Bobby
@Bobby: We don't know that <code>len</code> is <code>str.length()</code>
Stefan Kendall
+1  A: 

Hard to tell from a single line of code, but why are you initializing i, and the checking and decrementing index? Try:

for (int index = len-2; index>= 0; index --)

zakk