Code not working getting error
@Aayush-Mahajan-2206170693038609
There are a few issues with your code. FIrst of all the run-error can be resolved with adding a return statement in the first if condition i.e. the base condition or your code simply runs in infinite recursive calls.
After this your code will compile successfully but does not give any output.
Here’s my suggestions to resolve these issues
Put the second recursive call in an else block and do changes in out string before you make that recursive call or your code simply does nothing if the character is present for a single time.
#include
using namespace std;
char* remove(char *a,char s){
if(a[0]==’\0’){
s[0]=a[0];
return s;
}
if(a[0]==a[1]){
s[0]=a[0];
s[1]=’’;
return remove(a+1,s+2);
}
else{
return remove(a+1,s+1);
}
}
int main() {
char c[100000],b[100000];
cin>>c;
cout<<remove(c,b);
return 0;
}
still not working ,i tried entering a return type also
@Aayush-Mahajan-2206170693038609
The same problem with your code still persists. You are modifying the string s in case a character is repeated however you are doing nothing in case it doesn’t. You simply make the call to the next part without adding the current non-repeating character in your string ‘s’ . This is the main issue.
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.