When to use xalloc() when reading string values?

Steve Creps creps at silver.bacs.indiana.edu
Thu Feb 18 12:08:17 AEST 1988


   I'm running into a little confusion using strings in C, namely when
should I allocate space for them? I would appreciate any hints or rules-
of-thumb to use. The main problem I'm having is in a routine I'm writing
which reads strings into fields of a struct type. The strings are of
unknown length before I read them. Do I need to call an alloc() routine
first? The problem with this is how can I know how much to allocate? Also,
since they are returned by the routine, when should I free the space used
for them?
   Thanks in advance, as they say.

Disclaimer: I know quite a bit more about C than this question makes it sound.

-	-	-	-	-	-	-	-	-
Steve Creps on the VAX 8650 running Ultrix 2.0-1 at Indiana University.
creps at silver.bacs.indiana.edu, ...iuvax!silver!creps, creps at iubacs.bitnet
"Louisville Slugger baseball bats are made in Indiana"



More information about the Comp.lang.c mailing list