X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f From: Aaron Evans Newsgroups: comp.lang.c,comp.os.msdos.djgpp,comp.lang.c++ Subject: Re: String substitution to another Date: 10 Dec 2001 15:35:11 GMT Lines: 64 Message-ID: <9v2knf$htt$0@216.39.135.9> References: <3C151123 DOT D1E94FE8 AT surfeu DOT fi> <3c149894 DOT 7181858 AT news DOT tiscali DOT nl> NNTP-Posting-Host: 216.39.135.9 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; U; Linux 2.2.16-22 i586; en-US; rv:0.9.1+) Gecko/20010606 X-Accept-Language: en-us To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Richard Bos wrote: > "Mr. Veli Suorsa" wrote: > > >>>"Mr. Veli Suorsa" 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: >>>. >>> >>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);