Hello.
I'm trying to create a game and in that game, the AI that I will make should fill in his TURN file depending on the STATE file of both my AI and the opponent's. The server will provide these data. I'm trying to read the STATE file and put it into my struct
At first, I thought about making the parameters for the STATE file and TURN file included in structs.(Actually, I'm supposed to use it this way, lol)
I have made a sample STATE file so I would "fscanf" it. So, I decided to test and check if I'm able to read the first line. My STATE file looks like this:Code:struct Statefile{ char* tank1Fired; char* tank2Fired; char* tank1Alive; char* tank2Alive; int mapDimensionsX; int mapDimensionsY; int tank1PositionX; int tank1PositionY; int tank2PositionX; int tank2PositionY; int shellVelocity; int initialAmmo; int initialFuel; }State; struct Statefile *s =&State; struct Turnfile{ char* firing; int targetX; int targetY; char* movement; } Turn; struct Turnfile *p = &Turn;
And this is how my code look like:mapDimensions 32 24
shellVelocity 10
initialAmmo 100
initialFuel 50
tank1Position 1 12
tank2Position 30 12
tank1Fired false
tank2Fired false
tank1Alive true
tank2Alive true
these captions are unwanted as my programme would just fill in numbers/statesCode:FILE *outfile, *infile; char unwanted[10]; char buffer1 [30]; char buffer2 [30]; int t=1; sprintf(buffer1, "p%dt%03d.state", i, t); /* i is the number of player, which is the command line argument's number located to my programm */ infile = fopen (buffer1,"r"); fscanf(infile, "%s %d %d", unwanted[1], &s->mapDimensionsX, &s->mapDimensionsY);
mapDimensions
shellVelocity
initialAmmo
initialFuel
tank1Position
tank2Position
tank1Fired
...
My problem:
" The variable 'unwanted' is being used without being defined " is the message I receive from running my programme.
Is there another way to just obtain the numbers/states and put them into my struct?
Thanks for reading =)



LinkBack URL
About LinkBacks


