for(j=0;j < len-i;j++ )

Assume len is 10 and i happens to be 0. That loop translates to this:


for(j=0;j < 10; j++)

So you will loop from 0 to 9. But your code has this: