Strings-remove duplicates

#include
#include
using namespace std;
char dup_char(char a[],int n,int i){
if(n==0){
return 0;
}
cout<<a[i];
if(a[i]==a[i+1]){
dup_char(a+2,n-2,0);
}
else
dup_char(a+1,n-1,0);
}
int main(){
char a[10];
cin>>a;
int n=strlen(a);

dup_char(a,n,0);

}
why this code is showing error?

@tishya_goyal please save your code on ide.codingblocks.com and share the link

@tishya_goyal for now i have done that for you https://ide.codingblocks.com/s/213307
made some changes as well (you dont need a return type because you are not returning anything)
it is not removing the last character if it is duplicate, so take care of that as well.

it is still showing errors…

@tishya_goyal yes it is giving incorrect output. Do you need help with that?

yess…i am not able to correct it.

@tishya_goyalso currently what you are doing is that if you print valid characters and check for repeats. if you come across a repetition, you jump 2 indices, instead of 1. But this wont work if there are odd number of repetions, because for eg,
aaa
now we call for arr, we print arr[0], and see that a[0] == a[1], so we call the function for arr+2, now the character is a, but it will be printed as well, because it does not fail any conditions.

What you can alternatively do is, actually delete the repetitive element from the array, and next time call for arr only (because now the next element will be shifted 1 space backwards because of deletion, and we have to check that too. if we call for arr+1 then we would have moved one space forward and wont be able to check it against the current element). look at the below example to make sense of what i just said
for eg in aaabbbccc
you come across a, you see that next element is also a, so you delete either the next element or the current element and the string becomes aabbbccc. call for arr again.
again you are at the same a, you see next element is a, you delete a, the string becomes abbbccc
now a != b, so you can call for arr+1

@tishya_goyal deletion in array has to be done manually, which can be tedious, So you can consider using the “string” datatype instead of a character array. It works the same way, but it has better inbuilt functions which can be really helpful.

could u please make changes in my code.I’m not able to rectify it.

#include
#include
using namespace std;
void dup_char(char a[],int n,int i){

if(n==0){
	return ;
}
if(a[i]!=a[i+1]){
	cout<<a[i];
}
dup_char(a+1,n-1,0);

}
int main(){
char a[10],b[10];
cin>>a;
int n=strlen(a);

dup_char(a,n,0);

}
whats wrong in this code?

@tishya_goyal please share your code by saving it on ide.codingblocks.com
Again, you are not actually deleting any elements, if you dry run this program you will see why this is giving wrong ouput.

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.