1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#define x_r 32000
#define y_r 3200
void SaveMapToFile(int map[x_r][y_r], const std::string & strFile)
{
FILE * fp = fopen(strFile.c_str(), "wb");
if (!fp) throw CAppException(eApp_FileCreateError, "Error Creating File [%s] due to [%s]", strFile.c_str(), strerror(errno));
int nBytesToWrite = sizeof(int) * x_r * y_r;
int nBytesWritten = fwrite(map, sizeof(char), nBytesToWrite, fp);
fclose(fp);
if (nBytesWritten != nBytesToWrite) throw CAppException(eApp_FileWriteError, "File Write Error [%s] - nBytesWritten [%d] != nBytesToWrite [%d] due to [%s]", strFile.c_str(), nBytesWritten, nBytesToWrite, strerror(errno));
}
void LoadMapFromFile(int map[x_r][y_r], const std::string & strFile)
{
FILE * fp = fopen(strFile.c_str(), "rb");
if (!fp) throw CAppException(eApp_FileOpenError, "Error Opening File [%s] due to [%s]", strFile.c_str(), strerror(errno));
int nBytesToRead = sizeof(int) * x_r * y_r;
int nBytesRead = fread(map, sizeof(char), nBytesToRead, fp);
fclose(fp);
if (nBytesRead != nBytesToRead) throw CAppException(eApp_FileReadError, "File Read Error [%s] - nBytesRead [%d] != nBytesToRead [%d] due to [%s]", strFile.c_str(), nBytesRead, nBytesToRead, strerror(errno));
}
|