Need help fixing bugs in data parsing program

This is a discussion on Need help fixing bugs in data parsing program within the C Programming forums, part of the General Programming Boards category; Hi,
I'm working on a lab project to parse data into its proper format and output to screen & file. ...

Need help fixing bugs in data parsing program

Hi,

I'm working on a lab project to parse data into its proper format and output to screen & file. However, I have encountered some bugs where I can't determine their origin. I've modularly tested & reviewed my parsing functions & they seem ok. I will modularly review the output functions but in the meantime, I think they are supposed to be ok.

I need to find where my bugs are coming from to fix them. There are 2 major bugs: 1) output different from intended output and 2) output not sent to output file for some reason, though my code should be correct, output only sent to screen. However, the output file was created successfully, but why won't my program write to it.

It seems the previous output is kept in memory & new output is appended to it when that shouldn't be the case. But I can't find where that happens in my code as the previous output should have been flushed out for new output.

---------
I know debugging is one of the worst parts of programming BUT I can't do it all myself, so I really need your help here to find my bugs. All help appreciated.

NOTE: The source code is some length but I've commented half the code. If you've looked over the project info, I've used the decimal equivalents to check for ASCII delimiters (",", ":") and HEX values for line feed/new line & carriage return in my input parsing subfunctions. And data is truncated while parsing input. If you have any questions about my code, let me know.

I haven't read the C99 standard, but I believe it is legal there? Someone feel free to correct me here. The chances are, your compiler is probably not a C99 compiler, so unless you're compiling this as C++, this won't compile.

You might want to try flushing your output streams.

Code:

fflush( outfile );

Other than that, I didn't feel up to rewriting it so it was readable. Your single-indenting is really unreadable.

I forgot to mention my program hangs when outputting data, it stops before outputting the last record or line. So I would guess the file write operation was not performed as the program terminated abnormally & the file output was in the memory buffer the whole time.

I fixed the screen output error but still need help to find out why program gets stuck outputting last record.

much thanks for your hint, Hammer, it was the while loop that looped infinitely. And the compiler warned me about that too but I didn't figure that to be true.

Here's the thing though, the while loop works ok when the byte is retrieved as an int type as I did with a hexdump program. But why does it loop infinitely when the type is changed to unsigned char? is unsign giving it problems or char? I would like to know why.