Doubt in this code

If I change string to character array I am getting the right answer but why is that?

@akash_281 cause you are treating string like array in your pi( ) function.you are replacing str[i] to str[i+4] in your function but what if i+4 increase string size.

Yes, understood thanks