home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!mips!sdd.hp.com!uakari.primate.wisc.edu!daffodil!wyvern!alpha
- From: alpha@wyvern.twuug.com (Joe Wright)
- Newsgroups: comp.lang.c
- Subject: Re: Allocate memory to typed in string, How?
- Message-ID: <1992Aug13.184911.376@wyvern.twuug.com>
- Date: 13 Aug 92 18:49:11 GMT
- References: <MJN.92Aug9012538@pseudo.uucp>
- Organization: Box 68621, Virginia Beach, 23455
- Lines: 13
- X-Newsreader: Tin 1.1 PL4
-
- Attempts to allocate memory, char at a time, to an arbitrary 'string'
- is silly even if it is possible. If a string is assumed to be a line
- of a text file or arbitrary keyboard input, we can easily declare that
- it must not be longer than (let's say) 256 bytes. Given that screens
- are usually 80 to 132 chars wide, 256 will be wide enough for the
- Ivory standard (99.44 % pure). Having captured the line in our big
- static buffer we can easily determine its length and allocate memory
- and/or file space for the actual string. If you don't like static
- strings, allocate 256 bytes, read the 'string' into it, find its length,
- allocate that much (+1) and copy it. Lots faster..
-
- --
- Joe Wright alpha@wyvern.twuug.com
-