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: C
About this entry
You’re currently reading “
- Published:
- 6:37 am
- by -
3 Comments (Post a Comment)