'typedef struct' and 'struct'
Hi. I'm having a bit of a problem and it may be a problem of understanding the concept of typedef struct and struct. It's about how to access them I believe.
At first, I have these part-structs in my header:
Code:
struct Statefile{
unsigned short int tank1Alive;
unsigned short int tank2Alive;
unsigned short int mapDimensionsX;
unsigned short int mapDimensionsY;
unsigned short int initialFuel;
unsigned short int initialAmmo;
}State;
struct Statefile *s =&State;
struct Turnfile{
char* firing;
unsigned short int targetX;
unsigned short int targetY;
unsigned short int movement;
} Turn;
struct Turnfile *p = &Turn;
The Statefile struct gets its parameter filled by reading from the textfile. The Turnfile struct is to write a file called (whatever).tmp (for the time being then be converted to .turn <<nvm>>).
Then I have defied this struct:
Code:
typedef struct {
unsigned short int xMap;
unsigned short int yMap;
unsigned short int alive1;
unsigned short int alive2;
unsigned short int Ammo;
unsigned short int Fuel;
char* Move;
} tankState;
To get them filled, I used this function in my main:
Code:
tankState get_State( unsigned short int xMap, unsigned short int yMap, unsigned short int Ammo, unsigned short int Fuel, char* Move, unsigned short int alive1, unsigned short int alive2)
{
tankState t;
t.alive1 = alive1;
t.alive2 = alive2;
t.Ammo = Ammo;
t.Fuel = Fuel;
t.xMap = xMap;
t.yMap = yMap;
t.Move = Move;
return t;
}
Then I want my program to a use this function to do stuff ( I'm designing an Algorithm AI ).
Code:
tankState tank_move( tankState a, tankState b, tankState c, tankState d, tankState g, tankState i, tankState m)
{
tankState t;
t.alive1 = b.alive1;
t.alive2 = c.alive2;
t.Fuel = a.Fuel;
t.xMap = g.xMap;
t.yMap = i.yMap;
t.Move = m.Move;
t.Ammo = d.Ammo;
{
my commands
}
return t;
}
So, the function usage in my main looks like ( I used a combination (the arguments of tank_move) of what I thought may work to show you):
Code:
get_State(s->mapDimensionsX, s->mapDimensionsY, s->initialAmmo, s->initialFuel, p->movement, s->tank1Alive, s->tank2Alive);
if(s->initialFuel >0 && s->tank1Alive==1 && s->tank2Alive==1 && (s->tank1Fired==0 && s->tank2Fired==1)
{
tank_move(tankState.xMap, tankState.yMap, tankState.Fuel, tankState.Move, tankState.xPosition1, tankState.yPosition1, s->tank2PositionX, s->tank2PositionY, s->tank1Alive, s->tank2Alive);
}
When I insert "tankState.(whatever)", it says "illegal use of tankState"
And when I use "s->(whatever)", it says "cannot convert from tankState to unsigned short".
So, my question is: How can I fix my problem ?
Thank you for reading =)