1

This is a loop inside other loops, s[] is a char array. By this I am moving char step by step.what should I do for correcting it

for(k=j; s[k]!='\0' ;k++)    
{                         
   s[k]=s[k+1];                          
}
Lucky
  • 16,787
  • 19
  • 117
  • 151
Manmohit
  • 11
  • 1

1 Answers1

1

You should realize that arrays in Java have a length, so your null terminated check is wrong. Since you access the k+1'th element inside the loop, k must not go beyond s.length - 2.

for(k=j; k < s.length - 1 ;k++)
{ 
    s[k]=s[k+1];   
}
Eran
  • 387,369
  • 54
  • 702
  • 768