View Single Post
Old 10-29-2004, 05:47 PM   #6 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
The main() follows below. But first read this link:
Text program
Note what I have to say about file i/o handling. Next time I want to see that back in your code :).

Also, you know what wait_for_enter() is by now.

Code:
int main(int argc, char *argv[])
{
   string word, wordreverse;
   ifstream in_file("c:/Temp/scrabble.txt");  // open a file at this location
   if( !in_file )
   {
      cout<<"Opening file failed."<<endl;
      wait_for_enter();
      return 1;
   }
   
   unsigned size;
   while( in_file >> word )
   {
      size = word.size();  // count number of letters in the word
      while( size > 0)
      {
         wordreverse += word[size-1];
         --size;
      }
      // compare the two words
      if( word == wordreverse )
      {
         cout << word << " is a palindrome." << endl;
      }
      //Reset the reversed word for new iteration.
      wordreverse="";
   }
   
   if( !in_file.eof() )
   {
      cout<<"Something went wrong during processing of file."<<endl;
      wait_for_enter();
      return 1;
   }
   
   //Line below: optional right now. in_file destructor will close it anyway.
   //in_file.close()

   wait_for_enter();
   return 0;
}
__________________
Valmont is offline   Reply With Quote