Need help ASAP assignment due in 2 hours.

im working on this program that creates a dictionary from a file and we add and delete words from that. for some reason my words arent being inserted here are my two functions:
bool Dictionary::InsertWordsIntoDict(string fileName)
{
ifstream fin;
string newWord;
bool process;
fin.open(fileName.data());
if (!fin)
{
cout << "The file does not exist and thus could not be opened." << endl;
return(process = failure);
}
else
{
fin >> newWord;
while (fin>>newWord)
{
process = SearchForWord(newWord);
if (process == success)
;
else
{
process == AddAWord(newWord);

}
}
}
fin.close();
return(Dictionary::success);
}
bool Dictionary::AddAWord(string word)
{
ifstream inFile;
ofstream outFile;
string fileName = "#.txt";
bool check = failure;
int letter = 0;
string newWord = word;

fileName[0] = toupper(newWord[0]);
inFile.open(fileName.data(), ios::app);
check = SearchForWord(newWord);
if(totalWordsInDict == maxWordsInDict)
{
check = failure;
return check;
}
if(numOfWordsInFile[letter] == maxWordsPerFile)
{
check = failure;
return check;
}
else
{

check = SearchForWord(newWord);
if(totalWordsInDict == maxWordsInDict)
{
check = failure;
return check;
}
if(numOfWordsInFile[letter] == maxWordsPerFile)
{
check = failure;
return check;
}
else
{
if(check == success)
{
outFile.close();
inFile.close();
check = failure;
return check;
}
else
{
letter = newWord[0] - 65;
numOfWordsInFile[letter]++;
totalWordsInDict++;
newWord[0] = tolower(newWord[0]);
outFile.open(fileName.data(), ios::app);
outFile << newWord << " ";
check = success;
return check;
}
}
bool Dictionary::SearchForWord(string word)
{
ifstream inFile;
string fileName = "#.txt"; //declares the file name to correspond \
to the first
bool check = success; //leter of each word form the file
string newWord = word;
string finWord;
fileName[0] = toupper(word[0]); //makes the first letter of each word a\
uppercase letter
inFile.open(fileName.data()); //opens the file without overiding its \
contents

if(!inFile) //fails if file does not exist
{
check = false;
return check; //returns failure
}
else
{
while(inFile) //while the file is open
{
newWord[0] = tolower(newWord[0]); //changes the first letter of each\
word to lowercase
finWord[0] = tolower(finWord[0]);
if(newWord == finWord) //checks if the word matches the w\
ord already in the file
{
check = success;
return check; //returns success
}
else

{
check = failure;
}
inFile >> finWord; //adds the word to the file
}
}
return check;
}

Last edited on
http://www.cplusplus.com/articles/z13hAqkS/


I have spent most of my evening mentioning this - code tags.

1
2
3
else
{
process == AddAWord(newWord);


== is equality comparison, = is assignment


It is not like is actually used.


> finWord[0] = tolower(finWord[0]);
out of bounds, on the first iteration findWord is empty.
Topic archived. No new replies allowed.