int main()
{
// Open the dictionary file and fill it here
ifstream in_file;
in_file.open("words.txt");
vector<string> store;
string word;
//in_file >> word;
while (in_file >> word)
{
store.push_back(word);
}
// Ask the user for the file to process
cout << "Enter file name: ";
string fname;
cin >> fname;
ifstream fin;
fin.open(fname.c_str());
if (fin.fail())
{
cerr << "File does not exist" << endl;
return EXIT_FAILURE;
}
// Don't change this
clock_t start = clock();
// Open it and check it here
string word2;
vector<string> str_wrd2;
while (fin >> word2)
{
str_wrd2.push_back(word2);
}
fin >> word2;
for (int i = 0; i < word2.length(); i++)
{
if (islower(word2[i]))
{
isupper(word2[i]);
}
if (!isalpha(word2[i]))
{
fin.unget();
}
}
cout << "This word is not contained in the Dictionary: ";
for (int i = 0; i < word2.length(); i++)
{
if (str_wrd2[i] != store[i])
{
cout << str_wrd2[i];
}
}
// Don't change this
clock_t end = clock();
cout << "Time to check is " << (end - start) / CLOCKS_PER_SEC
<< " seconds. " << endl;
return 0;
}
This is what i have so far and entering moby.txt this prints out
Enter file name: moby.txt
This word is not contained in the Dictionary: MOBYDICK;ORTHEWHALEbyHermanTime to check is 0 seconds.
im pretty sure it has something to do with the while loops but dont know what it is. any help would be much appreciated thank you =]
oh and this is the pseudocode:
Open words.txt dictionary
Read the file, storing each word in a vector of string
Ask the user for the file to check and open the file
For each word in the file
Strip out any non-alpha characters and convert word to lowercase
If the word is not contained in the dictionary, print it
Print the number of "misspelled" words printed