#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main () {
/*** Declarations ***/
string fileName, Unchecked_Word, Dict_Word;
ifstream readFile, Dictionary("dictionary.txt");
/*** Program Introduction ***/
cout<< "~~~~~~ Super Speller 4000 ~~~~~~" << endl;
cout<< "\nPlease enter the file to be spell-checked: ";
cin >> fileName;
readFile.open(fileName);
if(readFile.is_open())
{
while(!readFile.eof())
{
//Reads a word in the file, and saves it as a string
readFile >> Unchecked_Word;
/*** String Manipulation ***/
int length = Unchecked_Word.length();
for(int i = 0; i < length; i++)
{
//subtracts sentence structure points
if(Unchecked_Word.at(i) == '(' || Unchecked_Word.at(i) == ')' || Unchecked_Word.at(i) == ',' || Unchecked_Word.at(i) == '.' ||
Unchecked_Word.at(i) == '"' || Unchecked_Word.at(i) == '-' || Unchecked_Word.at(i) == ' ' || Unchecked_Word.at(i) == '?')
{
Unchecked_Word.at(i) = ' ';
}
//Converts first letter in Unchecked_Word to lowercase
elseif(Unchecked_Word.at(i) <= 90 && Unchecked_Word.at(i) >= 65)
{
Unchecked_Word.at(i) = Unchecked_Word.at(i) + 32;
}
}
/*** SpellCheck Code ***/
/* Checks every properword in the dictionary and compares it to the check word.
Exits the loop once it hits the end of the dictionary and all words are
not equal to one another. Also exits loop if the the words are equal */
if(Dictionary.is_open())
{
for(int i(0); Dict_Word.compare(Unchecked_Word) != 0 && !Dictionary.eof(); i++)
{
Dictionary >> Dict_Word;
Dict_Word.compare(Unchecked_Word);
}
if(Dictionary.eof())
{
//Unchecked_Word.at(0) = Unchecked_Word.at(0) - 32;
cout << "\n" << Unchecked_Word;
}
}
//Spell Check Completion
else
{
cerr << "failed to open Dictionary..." << endl;
exit(1);
}
//Resets stream to beginning of dictionary file.
Dictionary.clear();
Dictionary.seekg(0, ios::beg);
};
}
else
{
cerr << "file failed to open..." << endl;
exit(1);
}
readFile.close(); //closes readFile
Dictionary.close(); //closes dictionary
/*** Program End ***/
cin.ignore(); cin.get(); return 0;
}
it is supposed to print all the words that are not found in the dictionary file