Let say our string is " abzx PI gf " now we find the pi at index 4 and 5 so we point j intiially to 6 and then increase the j till the last index value of the character array which is equal to 8 now we copy the char. to the last from right to left

now we copy like this
while( j > i+2 ){

arr [ j+2 ]=arr [ j ]
j–;

}
// how it is possible to store any character to j+2 index when j points to the last index of the character array .???

Hello @anshulgurawalia i didnt understand your doubt clearly but if your fount p at index ‘i’ and i at index at ‘i+1’ then you will make a jump of 2.

after pointing the j to the last index of the char.array we copy the elements from i+2 till the end
my ques is how we copy element by writing arr[j+2]=arr[j]( when j is pointing to the last index of the array index j+2 crosses our character array )

@anshulgurawalia make one separate character array and then do add the elements simultaneously in it.
don’t think that you will do after reaching the end only.

int j=i+2;
while(a [ j ] = ’ \0 ’ ){
j++;
}
so what is the meaning of this while loop

@anshulgurawalia actually as such this while loop is wrong because the condition in this should be either a[j]==’\0’ or a[j]!=’\0’

please tell the mistake in this code :-

@anshulgurawalia check this :


i have corrected your code and commented the mistake:
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.