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
What is binary tree in c?
will u please send me the placement papers to my mail???????????????????
what do you mean by inline function in C?
Can we replace the struct function in tree syntax with a union?
What is the purpose of clrscr () printf () and getch ()?
What is a volatile keyword in c?
#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); }
Explain the difference between null pointer and void pointer.
Can we assign string to char pointer?
please send me the code for multiplying sparse matrix using c
if p is a string contained in a string?
What is the size of a union variable?
What are the different types of linkage exist in c?
please explain every phase in the "SDLC" in the dotnet.
How do you do dynamic memory allocation in C applications?