Hi, Im having this problem in which the program freezes, the the code in the function called doesn't execute. Help would be much appreciated.
// spellchecker2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<cmath>
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
bool inDictionary(string word, string dictionary[]);
void wordFilter(string& word);
void spell(string& filename);
//This function takes a file and spell checks it
//@param file name
void spell(string& filename)
{
ifstream file;
string line,word,character;
file.open(filename);
while(!file.eof())
{
getline(file,line);
for(int i=0;i<line.length(); i++)
{
//splitting off characters
character= line.substr(i,1);
if(character!=" ")
{
word+=character;
}
else
{
wordFilter(word);
word="";
}
}
}
return;
}
//This Function takes a word from input file and removes punctuations
//outputs word
//@param word that needs to be filtered
void wordFilter(string& word)
{
string word2=word;
string character;
string out;
ifstream source;
source.open("dictionary.txt");
string dictionary[197];
string line;
for(int i=0; i<197;i++)
{
getline(source,line);
dictionary[i]=line;
}
for(int i=0; i< word2.length();i++)
{
character= word2.substr(i,1);
if(character!="."||character!=","||character!=""""||character!="?"||character!="("|| character!=")")
{
out+=character;
}
}
if(inDictionary(out,dictionary)==true)
{
cout<<out<<endl;
}
return;
}
//This function Returns True if the word is in the dictionary
//@param Strings needed to be checked
//@return True/False based on implemented algorithm
bool inDictionary(string word, string dictionary[])
{
for(int i=0;i<197;i++)
{
if(word==dictionary[i])
{
return false;
}
}
return true;
}
//This is the main Function
//@return Succesful termination of the program
int _tmain(int argc, _TCHAR* argv[])
{
string filename;
//file input
cout<<"Please enter a file to be checked: ";
cin>> filename;
//calls function
spell(filename);//does not execute
system("Pause");
return 0;
}
Additional thing is that I have to use this format as per assignment instuctions. The code should be working and i've spent hours trying to solve this problem. Thanks ahead of time.