Mail Archives: djgpp/2001/12/10/10:47:50
Richard Bos wrote:
> "Mr. Veli Suorsa" <veli DOT suorsa AT surfeu DOT fi> wrote:
>
>
>>>"Mr. Veli Suorsa" <veli DOT suorsa AT surfeu DOT fi> wrote:
>>>
>
> [This bit was me, though: ]
>
>
>>>Note also that this:
>>>
>>>
>>>> gets( filename );
>>>>
>>>is an evil function, which you shouldn't use under any circumstances
>>>excepting physical duress above the "agony" level, and that this:
>>>
>>>
>>>> while ( !feof( fileptr ) )
>>>> {
>>>> fgets( strline, MAXLINELEN, fileptr );
>>>>
>>>> }
>>>>
>>>is not the best way to read a file, because:
>>><http://www.eskimo.com/~scs/C-faq/q12.2.html>.
>>>
>>Don't worry about "evil functions", Richard, code seems to work very
>>well.
>>
>
> That's what people thought before the Internet worm struck, yes. Believe
> you me: every single use of gets() is a mistake. Sooner or later, you
> _will_ get bitten by it.
> As for the bug involving feof(): have you read that page? The bug does
> exist. Mind you, it _is_ possible to use feof() correctly. It is usually
> needlessly involved, but it can be done. If you want code that is
> obviously correct, though, you usually want to avoid it.
>
>
>>No warnings, no errors in my test compiler as usual ;-)
>>
>
> So? I can write programs that are syntactically correct, and perfect C,
> but that will print insults to my boss' heredity when run. I do not
> expect a C compiler to catch logic errors, only syntax errors.
>
> Richard
>
how is
gets(filename) || length > MAXLINELENGTH
more dangerous than
fgets (strline, MAXLINELENGTH, fileptr);
- Raw text -