0% found this document useful (0 votes)
139 views

C Program To Remove Consecutive Repeated Characters From String

This C program removes consecutive repeated characters from a string. It takes a string as input, calculates the length, then iterates through the string. If two consecutive characters are the same, it shifts all subsequent characters left by one and increments the length reduction count. This removes repeats while maintaining the original string length. The modified string is then printed without consecutive duplicates.

Uploaded by

Ronit Deb
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views

C Program To Remove Consecutive Repeated Characters From String

This C program removes consecutive repeated characters from a string. It takes a string as input, calculates the length, then iterates through the string. If two consecutive characters are the same, it shifts all subsequent characters left by one and increments the length reduction count. This removes repeats while maintaining the original string length. The modified string is then printed without consecutive duplicates.

Uploaded by

Ronit Deb
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

/*C program to remove consecutive repeated characters from

string.*/

#include <stdio.h>

int main()
{

char str[100];
int i,j,len,len1;

/*read string*/
printf("Enter any string: ");
gets(str);

/*calculating length*/
for(len=0; str[len]!='\0'; len++);

/*assign 0 to len1 - length of removed characters*/


len1=0;

/*Removing consecutive repeated characters from string*/


for(i=0; i<(len-len1);)
{
if(str[i]==str[i+1])
{
/*shift all characters*/
for(j=i;j<(len-len1);j++)
str[j]=str[j+1];
len1++;
}
else
{
i++;
}
}

printf("String after removing characaters: %s\n",str);

return 0;
}

You might also like