simple spell check.

Hey, I appreciate any help. I'm stuck and don't know what I've done wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <fstream>
#include <string>

using namespace 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
					else if(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
What do you get, instead?
For debuggin purposes, I'd add some lines to see if the code is doing what is intended:

On line 43 of your snippet

cout << Unchecked word << endl; // is the word correctly formatted?


On line 59

1
2
cout << Dict_word << " ";; // should print a lot of words... is the word of the dictionary file being                    
                           // correctly read? 


And so on...
Topic archived. No new replies allowed.