Article View: comp.std.c
Article #3705Re: gets() and getchar
From: Barry Margolin
Date: Fri, 11 Aug 1995 17:01
Date: Fri, 11 Aug 1995 17:01
25 lines
1665 bytes
1665 bytes
In article <40fn05$686@kruuna.helsinki.fi> wirzeniu@cc.Helsinki.FI (Lars Wirzenius) writes: >A.Main@dcs.warwick.ac.uk (Zefram): >> In any case, there's nothing wrong with using gets() >> in certain limited cases, even in production code. >It would be nice to hear some examples. For what it's worth, I don't >consider it sufficient to say that you write both the writer and the >reader: IMHO the program _must_ check the line length anyway (to avoid >the obvious and frequent bug where you or the poor user update only the >writer to use longer lines), and that can't be done with gets. While I'm certainly not a fan of gets(), I disagree with your claim that it shouldn't even be used when both the writer and reader are developed in conjunction. By your logic, strcpy() also should never be used, because someone might lengthen the source variable and forget to lengthen the destination variable. However, since gets() reads from stdin, it's very easy for users to arrange to feed it input from some other source than the matching writing application, so it's usually a disaster waiting to happen. -- Barry Margolin BBN PlaNET Corporation, Cambridge, MA barmar@bbnplanet.com Phone (617) 873-3126 - Fax (617) 873-5124
Technical Details
Message-ID:
<40g2cl$co7@tools.near.net>Path:
arc1-ca.pugleaf.net!tools.near.net!not-for-mailReferences:
<40bqih$bft@caip.rutgers.edu> <1995Aug11.002333.20047@dcs.warwick.ac.uk> <40fn05$686@kruuna.helsinki.fi>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!tools.near.net!not-for-mail From: barmar@nic.near.net (Barry Margolin) Newsgroups: comp.std.c Subject: Re: gets() and getchar Date: 11 Aug 1995 13:01:09 -0400 Organization: BBN Planet Corp., Cambridge, MA Message-ID: <40g2cl$co7@tools.near.net> References: <40bqih$bft@caip.rutgers.edu> <1995Aug11.002333.20047@dcs.warwick.ac.uk> <40fn05$686@kruuna.helsinki.fi> NNTP-Posting-Host: tools.near.net