#undef NIL
#define NIL 0x00000000
struct line {
int linenumber;
char *text;
struct line *nextline = NIL;
}
struct line line1 = { 1, "text1", NIL };
struct line line2 = { 2, "text2", NIL };
struct line line3 = { 3, "text3", NIL };
line1.nextline = &line2;
line2.nextline = &line3;
That works.
But the problem is I want to be able to create an unlimited number of list items. I want them to be generated automatically, rather than having to individually create them. In order for this to happen, they can not all have names, because obviously I can not give a unique name to all of possibly hundreds of structures.
I have tried linking a structure to an unnamed item, using the following methods:
linex.nextline = &{ num, "", NIL};
*linex.nextline = { num, "", NIL };
linex.nextline = { num, "", NIL };
linex.nextline -> { num, "", NIL };
All of them generate a compiler error.
How do you implement a linked list with an unlimited number of automatically generated items?


Sign In
Create Account


Back to top









