Replacepi(((())))))

i ddin’t get the line from 17 to 20…please explain me
#include
#include
using namespace std;

void replace(char *a, int i)
{
// base case
if (a[i] == ‘\0’ || a[i + 1] == ‘\0’)
{
return;
}

// recursive case
if (a[i] == 'p' && a[i + 1] == 'i')
{
    int j = i + 2;
    while (a[j] != '\0')
    {
        j++;
    }
    while (j >= i + 2)
    {
        a[j + 2] = a[j];
        j--;
    }

    // copy the pi
    a[i] = '3';
    a[i + 1] = '.';
    a[i + 2] = '1';
    a[i + 3] = '4';

    // ask the recursion to solve the samller string
    replace(a, i + 4);
}
else
{
    // ask the recursion to solve the smaller string
    replace(a, i + 1);
}

}

int main()
{
char a[100];
cin.getline(a, 100);

int n = strlen(a);

cout << a << endl;

replace(a, 0);

cout << a << endl;
return 0;

}

hi @abhinavssr2003_eab0717682969e5c, it is for going till the end then shifting characters to make space first try writing the code using for loop then you’ll easily convert it to recursion

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.