Dynamically malloc()-able pointers in a struct?
K.LAUX
rkl1 at hound.UUCP
Tue Dec 27 00:12:46 AEST 1988
In article <448 at blake.acs.washington.edu>, phaedra at blake.acs.washington.edu (J. Anderson) writes:
>
> I have a small C syntax problem. Given I have a structure of
> with the following nature:
>
> struct xyzzy {
> int plugh;
> long black_rod;
> char *foobar; /* This wants to be a pointer to a variable-length
> * array
> */
> }
>
Try:
#include <malloc.h> /* or whatever include file your system has */
struct xyzzy s;
s.foobar = (char *) malloc (nbytes);
if (s.foobar == NULL) { /* don't forget to test for failure */
/* Error */
}
--rkl
More information about the Comp.lang.c
mailing list