This code not giving any answer replace all pi

As soon as you enter the function replaceAll(string s,int i)
string res = replaceAll(s,i+1), would again call itself. which would result in a call stack overflow.
Please tell a basic idea about your approach, and add a base case/ terminating condition on i.

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.

Still not giving any output

Not giving any output

@shivansh.sm1,
First of all your recursive function can reach to the end of the function without producing any output. There is error1.
Second your base case must be related to ‘i’ and not s.
Since you’re recursively changing the value of ‘i’ and not s.
Try giving another shot.
If it doesn’t help we can work some something out.

#include<iostream>
#include<string.h>
using namespace std;
string str="";
void replaceAll(string s,int i){
	if(s[i]=='\0'){
		return;
	}
    replaceAll(s,i+1);
	if(s[i]=='p' && s[i+1]=='i'){
		str+=s.substr(0,i)+"3.14"+s.substr(i+2);
	}
}
int main() {
	int t,i=0;
	string s;
	cin>>t;
	while(t--){
		cin>>s;
		replaceAll(s,i);
		cout<<str<<endl;
        str="";
	}
	return 0;
}

not giving correct output for 2nd case

@Yashwardhan_Gautam …

@shivansh.sm1
Hello shivansh,
are u still facing any issue in this problem?

@shivansh.sm1
Hello shivansh ,
I am marking ur doubt as resolved. if u face any issue in this problem then dm me (aman212yadav).

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.