23.03.2014, 19:07
Valid file handle means if the file was opened successfully, not if it exists.
You haven't checked for both (even though in the SaveHouses you haven't posted the part that writes).
You haven't checked for both (even though in the SaveHouses you haven't posted the part that writes).
pawn Код:
LoadHouses()
{
if(!fexist("apartments.cfg")) return 1;
new
szFileStr[1024],
File: iFileHandle = fopen("apartments.cfg", io_read),
iIndex;
if (iFileHandle) // valid handle
{
while(iIndex < sizeof(HouseInfo) && fread(iFileHandle, szFileStr))
{
sscanf(...);
// may some other code..
iIndex++;
}
fclose(iFileHandle);
}
return 1;
}
pawn Код:
SaveHouses()
{
new
szFileStr[1024],
File: fHandle = fopen("apartments.cfg", io_write);
if (fHandle) // valid handle
{
for(new iIndex; iIndex < MAX_HOUSES; iIndex++)
{
format(...);
fwrite(fHandle, szFileStr);
}
fclose(fHandle);
}
...
return 1;
}