Question: [Beginner code] I am writing a spell-check code that has to do the following: 1) Take a bunch of words from a dictionary file of

[Beginner code]

I am writing a spell-check code that has to do the following:

1) Take a bunch of words from a dictionary file of around 200 words and store them in a 2d array.

2) Read a letter

3) Compare if the word from the letter == word from the dictionary. (using binary search)

I just need help on using the strcmp function. I keep getting errors. I just want to be able to compile without errors.

#include #include using namespace std; int spellcheck( char dict[][30] , char wordfromletter[30] , int sizeoffile) { int start = 0; int middle; int point; int end = sizeoffile - 1; bool correct = false; while (!correct && start <= end) { middle = (start + end) / 2; if ((strcmp(dict[middle], wordfromletter)) == 0) // pass char array instead { // this means dict[middle] is the same word as wordfromletter } else if((strcmp(dict[middle], wordfromletter)) < 0) { // this means dict[middle] is lesser than wordfromletter } else { // this means dict[middle] is greater than wordfromletter } } middle = (start + end) / 2; return point; }; int main() { ifstream input1; ifstream input2; char dict[200][30]; char wordfromletter[30]; int correction = 0; int sizeoffile = 0; input1.open("dictionary.txt"); input2.open("letter.txt"); if (input1.fail()) { cout << "error opening file" << endl; system("Pause"); return 0; } if (input2.fail()) { cout << "error opening letter" << endl; system("Pause"); return 0; } for (int n = 0; !input1.eof(); n++) { input1.getline(dict[n], 30); ++sizeoffile; } while(!input2.eof()) // eof needed to be a function { input2 >> wordfromletter; correction = spellcheck(dict, wordfromletter, sizeoffile); } cout << correction; input1.close(); input2.close(); system("pause"); } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!