MariaColette Wrote:*rubs head*
http://pastebin.com/BBZjzhn3
This is my entire code right now.
When I run it to at least try to declare the number of words in file, it does nothing after entering the filenames. It might be caught in an infinite loop? Either way, it doesn't seem to go beyond the GetWord function. I'm sure I'm doing loads of things wrong here.
OK. Your main loop is
Code:
while (inF >> word)
{
GetWord(inF, lineNum, wordNum, word); //Read word.
numWords = numWords + 1; //Count number of words in file.
}
This loop never tests for eof(), and the code in GetWord() that's supposed to test for the terminator is not written either, so there is no way for the program to exit.
Also, if you do "inF >> word" you are eating up pieces of input, so GetWord()'s behavior will be wrong. If your idea here was just to count input words, comment out the call to GetWord. i.e., something like this:
Code:
while (! inF.eof())
{
inF >> word;
numWords++; // equivalent to numWords = numWords + 1;
}
But let's see if we can get GetWord to do something, at least.
The terminator bit should look like this
Code:
if (ch == ':')
{
inF >> ch;
if (ch != '0') ExitWithError("malformed input terminator");
inF >> ch;
if (ch != ':') ExitWithError("malformed input terminator");
inF >> ch;
if (ch != '0') ExitWithError("malformed input terminator");
linepos = wordpos = 0;
return;
}
your main program's loop should be
Code:
do
{
GetWord(inF, lineNum, wordNum, word);
numWords ++;
} while (lineNum > 0);
This will leave all the input processing to GetWord, who will signal the end of input to us by setting lineNum (and wordNum) to 0.
If you still have time (sorry, was sleeping again :-() I would like you to try replacing the "inF >> ch" in GetWord with "ch = NonWhiteSpace(inF)" (of course adding that function as I wrote it upthread).
Also your InsertWord function is perfect as it is. It doesn't need to determine the line because the line is passed to it. The way you would go about calling it is like this (main()'s main loop)
Code:
PARAGRAPH text;
do
{
GetWord(inF, lineNum, wordNum, word);
if (lineNum == 0) break; // exit the input loop if end of input has been detected
switch (lineNum)
{
case 1: InsertWord(text.Line1, wordNum, word); break;
case 2: InsertWord(text.Line2, wordNum, word); break;
... etc
}
} while (! inF.eof());