I have a struct:
struct room;
...
/*some more structs */
typedef struct {
int state;
int id;
struct room* north;
struct room* south;
struct room* east;
struct room* west;
creature* creatures[10];
} room;
And a function that prints the contents:
void printContentsOfRoom(room* r) {
printf("\nRoom %d:\n", r->id);
printf("\tState: %s\n", getState(r));
printf("\n\tNeighbors:\n");
if (r->north.id != -1)
printf("\t North: Room %d\n",((room*)r->north)->id);
if (r->east.id != -1)
printf("\t East: Room %d\n",((room*)r->east)->id);
if (r->south.id != -1)
printf("\t South: Room %d\n",((room*)r->south)->id);
if (r->west.id != -1)
printf("\t West: Room %d\n",((room*)r->west)->id);
printf("\n\tCreatures:\n");
for (int i = 0; i < 10; i++) {
creature* c = (creature*)r->creatures[i];
if (c) {
if (c == pc)
printf("\t %s\n",getType(c));
else
printf("\t %s %d\n",getType(c),c->id);
}
}
}
I'm trying to make it so that if the room id is set to -1 (set while the program runs), it does not print the information about that room. On compilation, I get the error "request for member 'id' in something not a structure or union."
Furthermore, I have tried setting the if condition r->north->id, and that returns the error "dereferencing pointer to incomplete type 'struct room'"