home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!eff!ibmpcug!dylan
- From: dylan@ibmpcug.co.uk (Matthew Farwell)
- Subject: Re: Allocate memory to typed in string, How?
- Organization: The IBM PC User Group, UK.
- Date: Sun, 16 Aug 1992 14:13:54 GMT
- Message-ID: <Bt2y77.4Dn@ibmpcug.co.uk>
- References: <MJN.92Aug9012538@pseudo.uucp> <1992Aug13.184911.376@wyvern.twuug.com> <1992Aug15.201359.3601@athena.mit.edu>
- Lines: 35
-
- In article <1992Aug15.201359.3601@athena.mit.edu> scs@adam.mit.edu (Steve Summit) writes:
- >P.S. Please, don't anyone get too steamed if it seems like I'm
- > branding you as "too lazy and/or stupid to do any better."
- > I frequently write little throwaway utilities with
- > arbitrary limits, because I'm lazy, too. You can perform a
- > cost/benefit analysis which may show that it's not
- > worthwhile to accept arbitrarily-large inputs: in a way,
- > that's just institutionalized laziness, but if the analysis
- > is accurate and well-founded it may well be perfectly
- > reasonable and nothing to be ashamed of.
-
- I submit that it is very easy to write code which does not have line
- length limits. To take the example of:
-
- char buf[512];
-
- while (fgets(buf, sizeof buf, stdin)) {
- /* do something with buf */
- }
-
- This is very easy to translate, all you need is something like fgetmfs
- from the c-news distribution..., ie
-
- #define fgetms(fp) fgetmfs(fp, -1, CONT_NO) /* unbounded read */
-
- char *buf;
-
- while (buf = fgetms(stdin)) {
- /* do something with buf */
- }
-
- This one small change does wonders. All you need to take the time to do
- is get & compile fgetmfs, and shove it into a library somewhere.
-
- Dylan.
-