void LoadWorld(char *sFileName)
{
FILE *pFile;
if((fopen(sFileName, "rb")) == NULL)
{
MessageBox(NULL, "Failed to load World", "Error", MB_OK);
exit(0);
}
for(y = 0; y < 12; y++)
{
for(x = 0; x < 32; x++)
{
fscanf(pFile, "%i", i);
World1_1[y][x] = i;
}
}
fclose(pFile);
}
🔒 Locked
File Loading
Advertisement
Original Post
I run this function but it crashes my program. Im new to file i/o so be gentle...
Try fscanf(pFile, "%i", &i);
EDIT: A bit more explanation: You need to pass the address of the variable you want the data read into, otherwise it will try to write at the memory that is the value of i. Obviously this won't work, so you have to make sure you're giving it a valid location in memory to write to.
Raduprv: :p
EDIT: A bit more explanation: You need to pass the address of the variable you want the data read into, otherwise it will try to write at the memory that is the value of i. Obviously this won't work, so you have to make sure you're giving it a valid location in memory to write to.
Raduprv: :p
nope, still get the "send error report" stuff.. :-/
my world array is
and I dont have a debugger... do I? :-/
int World1_1[12][32];and I dont have a debugger... do I? :-/
pFile = fopen(...)
if(pFile == NULL)
You never assigned pFile to anything, so its just pointing to some random place in memory.
CM
if(pFile == NULL)
You never assigned pFile to anything, so its just pointing to some random place in memory.
CM
DOH! Thats embarrising... slipped by all of us lol...
THANKS CONNER!
THANKS CONNER!
One more thing...
my map file is a long series of numbers...
this function seems to only read the first number and not the others...
I tried using fseek but no change...
my map file is a long series of numbers...
this function seems to only read the first number and not the others...
I tried using fseek but no change...
for(y = 0; y < 12; y++) { for(x = 0; x < 32; x++) { fseek(pFile, seek, SEEK_SET); fscanf(pFile, "%i", &i); World1_1[y][x] = i; seek++; } }shouldnt this go over one number eachtime its read and put that value to the next grid slot in my array?
[Edited by - glVertex3f on June 24, 2004 1:49:51 AM]
i tried, didnt work for me..
void LoadWorld(char *sFileName){ FILE *pFile; int seek = 0; if((pFile = fopen(sFileName, "rb")) == NULL) { MessageBox(NULL, "Failed to load World", "Error", MB_OK); exit(0); } while(1) { fscanf(pFile, "%i", &i); for(y = 0; y < 12; y++) { for(x = 0; x < 32; x++) { //fseek(pFile, seek, SEEK_SET); //fscanf(pFile, "%i", &i); World1_1[y][x] = i; //seek++; } } if(!fgets((char*)&i, sizeof(int), pFile)) break; } fclose(pFile);}Im not sure if im doin that fgets right though...
fseek.. its commented out ;-)
and im not sure what you mean about replacing fscanf.. I still used it
(sorry if im not getting this)
btw..
I ran a console app that loads the map file and prints out the values and instead of numbers betwen 0 and 5, it prints out seemingly random 6 digit numbers.. any idea why?
and im not sure what you mean about replacing fscanf.. I still used it
(sorry if im not getting this)
btw..
I ran a console app that loads the map file and prints out the values and instead of numbers betwen 0 and 5, it prints out seemingly random 6 digit numbers.. any idea why?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement