write a c program to remove all the duplicate characters in a
string and replace with single character?
ex:-input- AAABBBCCC
output- ABC
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / satya
//using the std::string class from namespace std.
#include<iostream>
using namespace std;
int main()
{
string myStr;
cout<<"enter new string.";
getline(cin,myStr);
cout<<"entered value is "<<myStr;
char ch;
bool m=false;
string newStr;
newStr.resize(1);
int k=0;
for(int i=0;i<myStr.length();i++)
{
ch=myStr[i];
for(int j=0;j<k+1;j++)
{
if(ch!=newStr[j]) m=false;
else { m=true; break;}
}
if(m==false)
{
newStr.resize(newStr.size()+1);
newStr[++k]=ch;
}
}
cout<<"\nAfter removing duplicate letters, string is "<<newStr;
}
Is This Answer Correct ? | 3 Yes | 0 No |
SIR PLS TELL ME THE CODE IN C LANGUAGE TO PRINT THE FOLLOWING SERIES 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1
What is a program flowchart and how does it help in writing a program?
will the program compile? int i; scanf(ā%dā,i); printf(ā%dā,i);
Tell me can the size of an array be declared at runtime?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
What are the advantages of using Unions?
Explain how do you list files in a directory?
helllo sir give me some information of the basic information the c as printf ,scanf , %d ,%f and why is the main use of these.
What is the process to generate random numbers in c programming language?
Is it possible to run a c program without using main?If yes HOW??
There are N egg baskets and the number of eggs in each basket is a known quantity. Two players take turns to remove these eggs from the baskets. On each turn, a player must remove at least one egg, and may remove any number of eggs provided they all belong to the same basket. The player picking the last egg(s) wins the game. If you are allowed to decide who is going to start first, what mathematical function would you use to decide so that you end up on the winning side?
what is stack , heap ,code segment,and data segment