Actually it's not like I couldn't just let you see. I'm just being a lazy fuck.
code
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
const int LENGTH=30;
void removePunct(string & str);
int searchDictionary(string dict[], string word, int start, int end)
{
if(end<start)
{ return -1; } //not found
int mid=(start+end)/2;
if(dict[mid]==word)
{ return mid; } //found
else if(dict[mid] < word)
return searchDictionary(dict, word,mid+1, end);
else
return searchDictionary(dict,word,start,mid-1);
}
int BinarySearch (char ary[][LENGTH], int size, char search_item[LENGTH]){
const int LENGTH=30;
int first = 0, last = size-1;
bool found = false;
int position = -1, middle;
while (!found && first <= last){
middle = (first + last) / 2;
if ((strcmp (ary[middle], search_item))==0){
position = middle;
found = true;
}
else if (ary[middle] < search_item)
first = middle+1;
else last = middle-1;
}
return position;
}
int main() {
const int DICT_SIZE=3000; //size of dictionary
ifstream dictIn; //dictionary file stream
ifstream docIn; //document file stream
string wordList [DICT_SIZE]; //wordlist dictionary file to be loaded
string dictionaryName ="american-english.txt";//name of dictionary
int j=0, l=0, w=0, pos;
char c;
string word = "";
string tempWord = "";
dictIn.open(dictionaryName.c_str()); //load dictionary
int howMany=0; //count length of dictionary
dictIn>> wordList [howMany];
while(dictIn) //read successful
{
howMany++; //count
dictIn>> wordList [howMany]; //read dictionary
}
char templist = wordList[howMany];
docIn.open("document.txt"); //open document
for (l=0; !docIn.eof(); l++){ //test letters and reduce to lowercase
docIn >> word;
for (int a=0; word[a]!=0; a++){
while (word[a]){
c=word[a];
word[a]= (tolower(c));
a++;
}
}
pos=BinarySearch(templist, j, word);
if (pos==-1){
cout << word << " misspelled!!" << endl;
}
}
docIn.close();
return 0;
tempWord = word;
int search = searchDictionary(wordList, word, 0, howMany);
if (search != -1)
cout << "The word " << word << " is spelled incorrectly." << endl;
bool finished = 0;
bool wordFound = 0;
int length = word.length();
int n = 0;
int e = 0;
string userInput = word;
while(search == -1 && e < length && !finished)
{
e++;
n = e - 1;
swap(word[n],word[e]);
search = searchDictionary(wordList, word, 0, howMany);
if (search != -1){
cout << "Did you mean " << word << "? (enter 0 for no, 1 for yes)" << endl;
cin >> wordFound;
if (wordFound)
{
finished = 1;
cout << "The word was " << word << "." << endl;
}
}
search = -1;
word = userInput;
n++;
if (e >= length){
cout << "The word " << word << " is spelled incorrectly." << endl;
finished;
}
}
}
/*Function to remove punctuation from string*/
void removePunct(string & str)
{
str.erase(remove_if(str.begin(), str.end(), static_cast<int(*)(int)>(&ispunct)),str.end());
}