In this lecture sir start for loop and initialise currently =1 and end at current=l-1 .But a[l-1] is the null character.so our for loop condition is from 1 to l-2.But sir uses 1 to l-1?
String removes consecutive duppicates
Hey @asif_h
Please reopen the doubt on the same content you are referring to
Or share Sir’s code here
Void removeDuplicates(char a[])
{
int l=strlen(a);
if(l==1 or l==0)
{
return;
}
int prev=0;
for(int current=1; current<l; current++)
{
if(a[current]!=a[prev])
{
prev++;
a[prev]=a[current];
}
}
a[prev+1]=’\0’;
return;
}
int main()
{
char a[1000];
cin>>a;
removeDuplicates (a);
return 0;
}
Hey @asif_h
a[l-1] is not null
Say we have a=“pox”
Here len =3
a[0]=p
a[1]=o
a[2]=x
a[3]=’\0’
See a[l-1]=a[2] is x