EDIT:Since it was asked, I'm using Visual Studio 2013 Ultimate and it has raised no warnings.
I'm somewhat new to C, and file i/o has always been an issue for me. How would I go about parsing key value pairs in the form of "keyName: valueName"? My issue comes into play because my values could be a string, a float, or an unsigned int.
I'm writing a game using SDL2 and I'm trying to keep as much of the config for individual actors in separate .actor files. Following some sample code I've managed to read the key portion of the pair via fscanf, however when I attempt to fscanf the value in to my actor I get an exception.
Player.actor
folder: images/Player/
scale: 1.0,1.0
color: 255,255,255,255
colorSpecial: 10,255,100,255
xOffset: 1
numAnimations: 3
name: idle
filename: playerIdle.png
length: 8
frameWidth: 39
frameHeight: 87
frameRate: 0.75
type: loop
name: attack
filename: playerPunch.png
length: 8
frameWidth: 50
frameHeight: 82
frameRate: 0.75
type: once
name: walk
filename: playerWalk.png
length: 7
frameWidth: 50
frameHeight: 82
frameRate: 0.85
type: loop
Code:
void LoadActor(Actor *actor, char *filename)
{
FILE * file;
char buf[512];
char* imageFile = "";
int i = 0;
file = fopen(filename, "r");
if (!file)
{
return NULL;
}
rewind(file);
while (fscanf(file, "%s", buf) != EOF) //this works
{
if (strcmp(buf, "numAnimations:") == 0) // this works
{
fscanf(file, "%i", i); // this doesn't?
continue;
}
}
}
fscanf(file, "%i", &i);
You need to pass the address. – Johnny Mopprewind(file);
is useless, you just open the file – brunocontinue
in thewhile
? you do not need it to loop ^^ – bruno