Duplicate character formatting

what’s the mistake in my code ?

Hey @coderajay03
there is no insert function for char* ,it exist for string but not char*
So u have to manually insert it or directly print the output in recursion

#include <bits/stdc++.h>

using namespace std;

void duplicate(char *s,int i){
   if(s[i]=='\0')
    return;
   if(s[i]==s[i+1]){

    // s.insert(i+1,'*');removed this 
    cout<<s[i]<<'*'; //added this
    // duplicate(s,i+2);//remove this 
   }
   else cout<<s[i];//adde this
   duplicate(s,i+1);
   return;

}

int main()
{
 char s[20005];
 cin>>s;
 int i=0;
 duplicate(s,i);
//  cout<<s;//removed this
 return 0;//added this
}

If this resolves your query then please mark it as resolved :slight_smile:

1 Like