write a c program to remove all the duplicate characters in a
string and replace with single character?
ex:-input- AAABBBCCC
output- ABC

Answer Posted / vikas

// removal of duplicate character form a given string
#include <string.h>
#include <stdio.h>

int main()
{
char os[30];
char ds[20];
int i=0,j=0, c;

printf("Enter string\n");
while ((c = getchar()) != '\n')
os[i++] = c;
os[i] = '\0';

ds[0] =os[0];
ds[1] = '\0';
i = 1;
while ( os[i] != '\0'){
j = 0;
while (ds[j] != '\0') {
if (ds[j] == os[i])
break;
else
j++;
}
if (ds[j] == '\0') {
ds[j] = os[i];
ds[++j] = '\0';
}
i++;
}
printf("Original string = %s\n", os);
printf("modified string = %s\n", ds);
return 0;
}

Is This Answer Correct ?    13 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is binary tree in c?

622


will u please send me the placement papers to my mail???????????????????

1367


what do you mean by inline function in C?

618


Can we replace the struct function in tree syntax with a union?

780


What is the purpose of clrscr () printf () and getch ()?

595






What is a volatile keyword in c?

638


#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }

772


Explain the difference between null pointer and void pointer.

669


Can we assign string to char pointer?

588


please send me the code for multiplying sparse matrix using c

1726


if p is a string contained in a string?

1404


What is the size of a union variable?

598


What are the different types of linkage exist in c?

613


please explain every phase in the "SDLC" in the dotnet.

2180


How do you do dynamic memory allocation in C applications?

630