Problem reading information from an Array saved to file
[...]
this has me completely stumped, any ideas?
Pete
Isn't is just that, in read_arrays(), you're opening the files with FILE_WRITE rather than FILE_READ? Reading and writing multi-dimensional arrays using FileReadArray() and FileWriteArray() does work.
Isn't is just that, in read_arrays(), you're opening the files with FILE_WRITE rather than FILE_READ? Reading and writing multi-dimensional arrays using FileReadArray() and FileWriteArray() does work.
LOL thankyou ... i had not spotted that. working fine now. sometimes you just need a second set of eyes!
Hi,
im having problems reading information out of a .dat file that an array has been saved into. i have two two dimensional Arrays,
int GridTracker[100][15];
int GridStatus[10][10];
i have a funtion that is writing that infomation to file
void write_arrays() // write data to a file to backup memory
{
int pgt,pgs;
pgt=FileOpen("panther-gt.dat", FILE_BIN|FILE_WRITE);
if(pgt>0)
{
Print("wrirte ", FileWriteArray(pgt, GridTracker, 0, 1500));
FileClose(pgt);
}
pgs=FileOpen("panther-gs.dat", FILE_BIN|FILE_WRITE);
if(pgs>0)
{
Print("write ", FileWriteArray(pgs, GridStatus, 0, 100));
FileClose(pgs);
}
}
when this function runs, the result of the FileWriteArray is 1500 and 100. i.e. the size of the arrays.
i have another function which then reads from the file
void read_arrays() // read data to a file to backup memory
{
int pgt,pgs;
pgt=FileOpen("panther-gt.dat", FILE_BIN|FILE_WRITE);
if(pgt>0)
{
Print(FileReadArray(pgt, GridTracker, 0, 1500));
FileClose(pgt);
Print(GetLastError());
}
pgs=FileOpen("panther-gs.dat", FILE_BIN|FILE_WRITE);
if(pgs>0)
{
Print(FileReadArray(pgs, GridStatus, 0, 100));
FileClose(pgs);
}
}
the result from both operations is zero, i.e. no items read. the result from GetLastError() is also zero, and the result from the FileOpen operations is 1 i.e successfull.
this has me completely stumped, any ideas?
Pete