spell checker!!

ok so I am trying to do this spell checker. I have both the dictionary and the word I am trying to check on text files. When i try to run it this weird output comes up.

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;


const int LENGTH=10;
int BinarySearch(char bs[][LENGTH],int size,char search[LENGTH]);

void main()
{
int position;
int x=0;
char dictionary[100][LENGTH];
char word[LENGTH+1];
ifstream ifst;
ifst.open("hello.txt");

if(ifst.fail())
{
cout<<"dictionary file opening failed \n";
}

for(int x=0; !ifst.eof();x++)
{

ifst.getline(dictionary[x],LENGTH);
cout<<dictionary<<endl;
}
ifst.close();

ifstream sent;
sent.open("sentence.txt");

if(sent.fail())
{
cout<<"sentence file not found \n";
}

for(int m=0;!sent.eof();m++)
{
sent>>word;
sent.getline(word,LENGTH);
cout<<word<<endl;
}


position=BinarySearch(dictionary,x,word);
if(position==-1)
{
cout<<"the word is mispelled \n";
}

else
cout<<"everything is correct \n";



}

int BinarySearch(char bs[][LENGTH],int size,char search[LENGTH])
{
int first=0;
int last=size-1;
int middle=0;
int compared;
int position=-1;

while(first<=last)
{
middle=(first-last)/2;
compared=strcmp(search,bs[middle]);
if (compared==0)
{
return middle;
}
else if(compared>0)
first=middle+1;
else
last=middle-1;
}
return position;
}



Output:

0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498

I seriously do not know what I am doing wrong!!
Please use the correct tags!!!
[Repost]
ok so I am trying to do this spell checker. I have both the dictionary and the word I am trying to check on text files. When i try to run it this weird output comes up.

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
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;


const int LENGTH=10;
int BinarySearch(char bs[][LENGTH],int size,char search[LENGTH]);

void main()
{
	int position;
	int x=0;
	char dictionary[100][LENGTH];
	char word[LENGTH+1];
	ifstream ifst;
	ifst.open("hello.txt");

	if(ifst.fail())
	{
		cout<<"dictionary file opening failed \n";
	}

	for(int x=0; !ifst.eof();x++)
	{
		ifst.getline(dictionary[x],LENGTH);
		cout<<dictionary<<endl;
	}
	ifst.close();

	ifstream sent;
	sent.open("sentence.txt");

	if(sent.fail())
	{
		cout<<"sentence file not found \n";
	}

	for(int m=0;!sent.eof();m++)
	{
		sent>>word;
		sent.getline(word,LENGTH);
		cout<<word<<endl;
	}


	position=BinarySearch(dictionary,x,word);
	if(position==-1)
	{
		cout<<"the word is mispelled \n";
	}
	else
	{
		cout<<"everything is correct \n";
	}
}


Output:

0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498
0055F498


I seriously do not know what I am doing wrong!!
[/Repost]

Now It Will Be A Lot Easier To Help You
Last edited on
A few errors:
cout<<dictionary<<endl;
This will print the address to the dictionary not the dictionary itself, maybe its meant to be:
cout<<dictionary[x]<<endl;

Also you need not declare x in line 14.
Apparently using .eof is not good (idk why) I always use .good() or .bad()

The following lines are the same:
1
2
sent>>word;
		sent.getline(word,LENGTH);


Binary Search is not implemented.

Please note that the above information could possibly have errors as I have not tested your code
Topic archived. No new replies allowed.