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
In which language linux is written?
struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer
A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream
how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....
Can math operations be performed on a void pointer?
1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321
Are bit fields portable?
What are 3 types of structures?
Explain how can you tell whether a program was compiled using c versus c++?
What is the size of empty structure in c?
in iso what are the common technological language?
What is the scope of an external variable in c?
What is the use of getchar() function?
Can you explain the four storage classes in C?
What is main function in c?