C++ Program – Remove duplication of the word

by Nideesh C on May 11, 2011 · 0 comments

in C++




//Downloaded From theonlinetutorials.com
//Source code
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void dop(char s[])
 {
 char a[100],b[100];
 a[0]=NULL;
 b[0]=NULL;
 int flag=0,sa=0;
 for(int i=0;i<=strlen(s);i++)
 {
 if(s[i]==' '||s[i]==NULL)
 {
 b[sa]=' ';
 sa++;
 b[sa]=NULL;
 flag=1;
 }
 else
 {
 b[sa]=s[i];
 sa++;
 }
 if(flag==1)
 {
 if(strcmp(a,b)==0)
 {
 for(int j=(i-sa);j<=strlen(s);j++)
 {
 s[j]=s[j+sa];
 }
 i=i-sa;
 }
 flag=0;
 sa=0;
 strcpy(a,b);
 }
 }
 }
int main()
 {
 char s[100];
 cout<<"Enter a String"<<endl;
 gets(s);
 dop(s);
 cout<<"Formated string is"<<endl;
 cout<<s;
 getch();
 return 0;
 }



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C++ Program – Reversing each word in a string
  2. Sample – Program to enter a string and find its length.
  3. C++ program – Lowercase Vowels
  4. C++ Program – Count no of repetitions of a digit
  5. C Program – To replace a word by another word in a given string

Leave a Comment

Previous post:

Next post: