Complete.Org: Mailing Lists: Archives: discussion: March 2000:
[aclug-L] Re: Weekly C quiz

[aclug-L] Re: Weekly C quiz

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: discussion@xxxxxxxxx
Subject: [aclug-L] Re: Weekly C quiz
From: John Goerzen <jgoerzen@xxxxxxxxxxxx>
Date: 13 Mar 2000 09:20:32 -0600
Reply-to: discussion@xxxxxxxxx

The easiest way is to look at the final character in your string.  If
it's a newline, you got the entire line and the next call will read in
the next line.  If not, then just loop until it is.

-- John

Larry Bottorff <mrprenzl@xxxxxxxxxx> writes:

> Here's the next installment of Larry's Weekly C Quiz. This week we're
> looking at buffer overruns. Here's some code:
> #define MAX_BUF 201
> ...
> char buffer[MAX_BUF];
> FILE *file_in;
> ...
> while (fgets(buffer, sizeof(buffer), file_in) != NULL) {
> ....
> }
> If fgets returns a line from file_in's file bigger than MAX_BUF, buffer
> is full at the maximun size, the rest not going into buffer: good. But
> then the next fgets seems to fill buffer with the leftover from the
> input file's last line. How can I "flush" fgets so a longer line's
> leftover doesn't show up in the next fgets?
> Larry
> -- This is the discussion@xxxxxxxxx list.  To unsubscribe,
> visit

John Goerzen   Linux, Unix consulting & programming   jgoerzen@xxxxxxxxxxxx |
Developer, Debian GNU/Linux (Free powerful OS upgrade) |
The 84,921,810th prime number is 1,716,124,699.

-- This is the discussion@xxxxxxxxx list.  To unsubscribe,

[Prev in Thread] Current Thread [Next in Thread]