Indefinite-length array as member of struct: how?
Charles Green
charles at c3pe.UUCP
Fri Jul 7 02:20:17 AEST 1989
I have an application where I'm building and manipulating a stack of
variable-length strings. I've set up a linked list of nodes, each one
declared as follows:
struct node {
struct node* next;
char string[];
} *nodeptr;
When I know how long the string is I'm pushing onto the stack, I say:
nodeptr = malloc(strlen(data)+5);
to cover the struct node* and terminating NULL, and then simply
strcpy(nodeptr->string, data);
The only problem I have is with compilation: I get a warning about the
zero-length element "string". I'd like to find out the "correct" way to
do this. I'll be glad to summarize any Emailed responses, of course.
Thanks, Charles Green charles%c3pe at decuac.dec.COM
--
{decuac.dec.com,cucstud,sundc}!c3pe!charles ex::!echo Boo:
More information about the Comp.lang.c
mailing list