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
I just typed in this program, and it is acting strangely. Can you see anything wrong with it?
What is the use of f in c?
Explain what is the difference between functions getch() and getche()?
What are the main characteristics of c language describe the structure of ac program?
WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?
Explain argument and its types.
What are global variables and explain how do you declare them?
There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?
Implement bit Array in C.
Which is best book for data structures in c?
main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above
What is main () in c language?
write a proram to reverse the string using switch case?
Why doesnt the call scanf work?
Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014 Npu university