Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program to read all words from a file and remove all words which are palindromes

Posted By: Easy Tutor     Category: C++ Programming     Views: 5845

Write a program that reads words from a text file and remove all words which are palindromes.

Code for Program to read all words from a file and remove all words which are palindromes in C++ Programming

 # include <iostream.h>
 # include <fstream.h>
 # include <string.h>
 # include <stdlib.h>
 # include <conio.h>

 int main( )
    {
       clrscr( );

       fstream file("CP-03.txt",ios::in|ios::nocreate);

       if(!file)
      {
         cout<<"\n Unable to open the input file."<<endl;
         cout<<"\n Press any key to exit.";

         getch( );
         exit(EXIT_FAILURE);
      }

       char Text_line[90]={NULL};

       file.getline(Text_line,80);

       int number_of_text_lines=atoi(Text_line);

       for(int counter=0;counter<number_of_text_lines;counter++)
      {
         strset(Text_line,NULL);

         file.getline(Text_line,80);

         int i=0;
         int j=0;

         char Word[80]={NULL};
         char Reverse_word[80]={NULL};

         do
        {
           strset(Word,NULL);
           strset(Reverse_word,NULL);

           j=0;

           do
              {
             Word[j]=Text_line[i];
             Reverse_word[j]=Text_line[i];

             i++;
             j++;
              }
           while(Text_line[i]!=' ' && Text_line[i]!=NULL);

           strrev(Reverse_word);

           if(strcmp(Word,Reverse_word)!=0)
              cout<<Word;

           if(Text_line[i]!=NULL)
              cout<<" ";

           i++;
        }
         while(Text_line[i]!=NULL);

         cout<<endl;
      }

       file.close( );

       getch( );
       return 0;
    }
  
Share: 



Easy Tutor
Easy Tutor author of Program to read all words from a file and remove all words which are palindromes is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!