Start traversing from the end and find position ' i - 1' of the first character which is greater than its successor .
int i ; for ( i = temp . length ( ) - 1 ; i > 0 ; i -- ) if ( temp [ i ] > temp [ i - 1 ] ) break ;