////////////////////////////////////////////////////////////////////// // // spellingmain.cpp // // Jeff Ondich 11/1/00 // Last modified 11/1/00 // // A simple spell checker. // // This program asks the user for the name of a file containing // a spelling list, then asks for the name of a text file, and // then prints out a list of the words that are contained in // the text file but not the spelling list file. // ////////////////////////////////////////////////////////////////////// #include #include #include "spellinglist.h" void CleanWord( string& theWord ); int main() { // Get the names of the files. string spellingListFileName; string textFileName; cout << "Spelling list file: "; cin >> spellingListFileName; cout << "Text file: "; cin >> textFileName; // Declare and initialize the spelling list. SpellingList spellingList( spellingListFileName ); // Open the text file. ifstream textFile( textFileName.c_str() ); if( ! textFile.is_open() ) { cout << "The file \"" << textFileName << " can't be opened." << endl; cout << "Perhaps it does not exist." << endl; exit( 1 ); } // Process the words. string word; cout << endl << endl << "Misspelled words" << endl; cout << "=================" << endl << endl; while( textFile >> word ) { CleanWord( word ); if( ! spellingList.IsIn( word ) ) cout << word << endl; } // Clean up after yourself. textFile.close(); return( 0 ); } ////////////////////////////////////////////////////////////////// // // CleanWord removes all non-alphabetic characters // from the given string (except for hyphens and // apostrophes), and reduces all upper case letters // to lower case. Thus, once CleanWord is done, theWord // consists entirely of lower case letters, hyphens, // and apostrophes. // ////////////////////////////////////////////////////////////////// void CleanWord( string& theWord ) { string s = ""; int originalLength = theWord.length(); for( int i=0; i < originalLength; i++ ) { char c = theWord[i]; if( isalpha(c) || c == '\'' || c == '-' ) s += tolower(c); } theWord = s; }