Re: need some help



Richard Heathfield wrote:

.... snip ...

2) the next stage is to write (or find) a function that can read
an entire line from standard input, reallocating storage as and
when necessary to ensure that there is sufficient room to store
the string. For a very simple way to do this that will suit you
very well, look for Chuck Falconer's ggets() function which,
last I heard, could be found at:

<http://cbfalconer.home.att.net/download/ggets.zip>

3) simply call this function in a loop, assigning each pointer
thus obtained to new[i], where i is your loop counter, running
from 0 to n-1. What will you do if the function returns NULL, to
indicate insufficient storage, or perhaps an absence of input data?

int ggets(char**) returns 0 for success, EOF for eof, and positive
for lack of memory. So a suitable read'em'all loop is:

while (0 == ggets(&buffptr)) { ... }

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

.



Relevant Pages

  • Re: Command line
    ... end loop; ... machine) a compiler error. ... > as standard input, or you could just pick up argument ...
    (comp.lang.ada)
  • Re: Standard input
    ... standard input of the fortran program. ... The second loop does not terminate: ... This can easily be solved by introducing a keyword like "QUIT" - ...
    (comp.lang.fortran)
  • Reading the while standard input into a String
    ... whole contents of the standard input into some place in memory, ... character by character into a temporary buffer, ... for J in To'Range loop ...
    (comp.lang.ada)
  • Re: Quick QSH question
    ... file is omitted and standard input is used, ... where it's getting input from stdin, just like I'm used to with Unix. ... how do you get out of it without sysreq-2? ... would commonly use ctrl-d to force an EOF condition and your command ...
    (comp.sys.ibm.as400.misc)
  • Re: compress all *.c files in a hierarchy?
    ... standard input see: man xargs ... in the loop to tar and then when the loop finishes, gzip the tar file. ...
    (comp.unix.shell)