Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algorithms and flowcharts (Yet another C++ assignment).
#21
Yeah, you deleted my line " ch = NonWhiteChar(inF);" which was the first one in the do {} loop.
That is where ch gets a value (which is the next character in the input file, skipping any whitespace).
You could replace it temporarily with "inF >> ch;" and make sure your input file has no blanks and such for now. Once that works, we can step up to dealing with the whitespace.
Reply
#22
SaptaZapta Wrote:Yeah, you deleted my line " ch = NonWhiteChar(inF);" which was the first one in the do {} loop.
That is where ch gets a value (which is the next character in the input file, skipping any whitespace).
You could replace it temporarily with "inF >> ch;" and make sure your input file has no blanks and such for now. Once that works, we can step up to dealing with the whitespace.

I actually did notice that and put it back in before; however, I still got the same error. Seeing your explanation, I'm even more confused as to why now. :|
Reply
#23
*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.
Reply
#24
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());
Reply
#25
I ran out of time, but that's all right, not your fault. I'm still going to at least get this to run, so I can at least understand the process.

I have yet another assignment due on the 28th (I don't know why on the 28th, he said he'd only assign a program once a week...), so I'll be coming back with more questions starting tomorrow. @_@ This one SEEMS like a short one, but I'll see once he lectures us on it tomorrow...

Thanks anyway, you've been a real help.
Reply


Forum Jump:


Users browsing this thread: