Qualifier-qualifier list expected before 'rooms'


I'm working on a DnD-Text-Based-Style C game, and I'm having a problem compiling my structure. Here is what I have for a structure so far:

typedef struct stats {                  //
    int strength;               //
    int wisdom;                 //
    int agility;                //
} stats;

typedef struct rooms {
    int n_monsters;
    int visited;
    rooms nentry;
    rooms sentry;
    rooms wentry;
    rooms eentry;
    monster *monsters;
} rooms;

typedef struct monster {
    int difficulty;
    char *name;
    char *type;
    int hp;
} monster;

typedef struct dungeon {
    char *name;
    int n_rooms;
    rooms *rooms;
} dungeon;

typedef struct player {
    int maxhealth;
    int curhealth;
    int mana;
    char *class;
    char *condition;
    stats stats;
    rooms c_room;
} player;

typedef struct game_structure {
    player p1;
    dungeon d;
} game_structure;

When I compile it, I get the error: structure.h:21: error: specifier-qualifier-list before 'rooms'

Can you help me figure out why this is? Is it because I'm calling rooms from the structure that contains rooms? Please help.

There are many many problems with this piece of code. The first is that a struct definition must know how much memory to allocate, and it cannot do this when it contains a type that has not been fully defined (this is why people recommend that you use a pointer, since the size of a pointer is known at compile time).

However, and this is important, simply changing to pointers will not solve the problem, since the first room* is encountered before the appropriate typedef completes. You would need to write something like:

struct rooms {
    int n_monsters;
    int visited;
    struct rooms *nentry;
    struct rooms *sentry;
    struct rooms *wentry;
    struct rooms *eentry;
    monster *monsters;
} rooms;

or perform a forward declaration (typedef struct rooms rooms;). You also need to make sure the monster type is defined or at least has a forward declaration.