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

A text file that contains declarations used by a group of functions,programs,or users a) executable file b) header file c) obj file d) .cfile

638


How many keywords are there in c?

586


What is pointer to pointer in c language?

593


program to convert a integer to string in c language'

1982


What are the types of pointers in c?

526






Where local variables are stored in c?

554


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

762


What is FIFO?

668


What is the use of getchar functions?

672


Write a client and server program in C language using UDP, where client program interact with the Server as given below: i) The client begins by sending a request to send a string of 8 characters or series of 7 numbers, the server sends back a characters or numbers as per the request of the client. ii) In case of series of 7 numbers: The client sends a multiplication of numbers, to the server. iii) In case of a string of 8 characters: The client sends a reverse order of string to the server.. iv) Server will send an acknowledgment to the client after receiving the correct answer

3839


How is a macro different from a function?

652


What is the Purpose of 'extern' keyword in a function declaration?

649


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

630


a c code by using memory allocation for add ,multiply of sprase matrixes

2297


What is a floating point in c?

598