File writing / reading problem (SOLVED)
Posted: Sun Feb 03, 2013 1:42 pm
Hello!
I'm having this little problem with file writing / reading..
I want to write a few pairs of integer values (x & y) indicating actor positions to file
and then load them and place actors to the right positions.
It works nearly perfectly. The only problem I keep getting is that the last actors position
isn't the one it should be, but instead it goes to the previous actors' position.
My writing code:
And my reading code:
It probably is some really simple thing that I just can't spot, and that's why I need someone else to take a look at my code.
Thanks in advance!
I'm having this little problem with file writing / reading..
I want to write a few pairs of integer values (x & y) indicating actor positions to file
and then load them and place actors to the right positions.
It works nearly perfectly. The only problem I keep getting is that the last actors position
isn't the one it should be, but instead it goes to the previous actors' position.
My writing code:
- Code: Select all
int spawnPos[2];
void writeLevelFile(char * filePath)
{
int i;
FILE * WRITE = fopen(filePath, "w+b");
for (i = 0; i < topIndex; i ++)
{
if (strcmp(getClone2("placeSpawn", i)->clonename, "") != 0)
{
spawnPos[0] = (int)round(getClone2("placeSpawn", i)->x - view.x);
spawnPos[1] = (int)round(getClone2("placeSpawn", i)->y - view.y);
fwrite(spawnPos, sizeof(spawnPos), 1, WRITE);
}
}
fclose(WRITE);
}
And my reading code:
- Code: Select all
int spawnPos[2];
void createSpawnPoints(char * filePath)
{
int i;
FILE * READ = fopen(filePath, "r+b");
while (!feof(READ))
{
fread(spawnPos, sizeof(spawnPos), 1, READ);
CreateActor("spawn", "spawn", "(none)", "(none)", spawnPos[0], spawnPos[1], false);
}
fclose(READ);
}
It probably is some really simple thing that I just can't spot, and that's why I need someone else to take a look at my code.
Thanks in advance!