You forgot something thereCode:struct node1 { int roomnumber; struct node1 *nextroom; }; // Need a semicolon here!!!!!! typedef struct node2 { int floornumber; struct node1 room; struct node2 *nextfloor; } floor;
You forgot something thereCode:struct node1 { int roomnumber; struct node1 *nextroom; }; // Need a semicolon here!!!!!! typedef struct node2 { int floornumber; struct node1 room; struct node2 *nextfloor; } floor;
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
stupid semicolon
but tell me, I have other problems. how do I acess the field "roomnumber"?
the red are my suggestions. I must admit, I am really flaky when it comes to structures in structures which both have pointersCode:floor *new2 = malloc(sizeof(floor)); new2->floornumber = 2; new2->nextfloor = NULL; new2->room->roomnumber = 201; new2->room.roomnumber = 201; new2.room->roomnumber = 201;
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Why do you need struct node2 *nextfloor as a member of struct node2 because IMO it'll always point to NULL?
Yup, that's why setting it to NULL didn't make sense in the code snippet posted by the o/p unless that's the top floor
yes it would point to a next node if there were one
you're right. i chose to have just the top floor.
thanks. so what about the pointer nextroom? which is it
Code:new2->room.nextroom = newroom; new2->room->nextroom = newroom;