I’ve made a binary tree where there are essentially three levels of structs:
typedef struct l {
char n[15];
struct l *next;
} List;
typedef struct {
char rname[20];
char lname[20];
List number;
} info;
typedef struct tree {
info thisnode;
struct tree *left;
struct tree *right;
} Tree;
and on this line of code
t->thisnode.number = t->thisnode.number.next;
I get the error mentioned in the title
Normally with recursive data structures these type of assignments work, despite next having type struct *l. Could anyone help me work out why in this case it isn’t working?
Also I would instinctively have the above line as
t->thisnode.number = t->thisnode.number->next;
But my compiler seems to like that even less.
Well, the types surely are incompatible.
The type of the
nextfield innumberisstruct l *, but the type ofnumberininfoisList, which is an alias forstruct l, i.e. the entire struct, not just a pointer to it. So you’re trying to assign a pointer into an entire structure, which won’t fly.It seems you’re missing a pointer level, perhaps the
numberfield ininfoshould beList *?