This code is written in a file named Monster.c. I have Monster.h defined in both my GameMain.c file and my Monster.c file. Inside the Monster.h file the code is:
#ifdef MONSTER_H_
#define MONSTER_H_
int Monster(int Selection);
EnemyStats MonsterStats(int Selection);
#endif
I then made my typedef struct in the Monster.c file and created the function to return the values for the struct.
typedef struct EnemyStats
{
int EnemyHP;
int VictoryExp;
int EnemyLevel;
}
EnemyStats;
EnemyStats MonsterStats(int Selection)
{
struct EnemyStats value;
switch(Selection)
{
case 1:
value.EnemyLevel = 1;
value.VictoryExp = 1;
value.EnemyHP = 1;
return value;
case 2:
value.EnemyLevel = 1;
value.VictoryExp = 1;
value.EnemyHP = 1;
return value;
...
}
In the GameMain.c file, I used this code to try and access the information stored in the struct:
EnemyStats result;
...
printf("%d", result.EnemyLevel);
It gives me the error when I use gcc GameMain.c Monster.c
GameMain.c:40:2: error: unknown type name ‘EnemyStats’
GameMain.c:61:25: error: request for member ‘EnemyHP’ in something not a structure or union
If I try to add struct before EnemyStats result; it gives me this error.
GameMain.c: In function ‘main’:
GameMain.c:40:20: error: storage size of ‘result’ isn’t known
I am unsure of what I am doing wrong. Any help is appreciated.
For anybody who does not know, I am using ... to say that I am skipping code that does not affect the situation I am describing or the code is redundant