C Programming - Remove Concequetive Repeting Chars with that Character

What I meant was convert "aaabccddd" to "abcd".

Solution:


#include < stdio.h >
#define STRING "aaabccddd"

int replaceCChars(char *string)
{
char *dest=string;

while(*string) {
if ( *string != *(string+1) ) {
*dest++ = *string;
}
string++;
}
*dest = '\0';
}

int main()
{
char a[]=STRING;
printf("Before: %s ",a);
replaceCChars(a);
printf("After: %s\n",a);
}


Labels:


About this entry