BOOL GameEngine::WriteHiScore(int hiscore,CHAR scorestore[6])
{
HANDLE hFile = CreateFile(TEXT("HiScore.dat"), GENERIC_WRITE, 0,NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile = INVALID_HANDLE_VALUE)
return false;
CHAR storescore[6];
DWORD scorebyteswritten;
//unsigned long int hiscore;
wsprintf( storescore, "%d", hiscore);
if(!WriteFile(hFile,storescore, 5, &scorebyteswritten, NULL))
{
CloseHandle(hFile);
return false;
};
WriteFile(hFile,storescore, 5, &scorebyteswritten, NULL);
return CloseHandle(hFile);
};
int GameEngine::ReadHiScore()
{
CHAR storescore[6];
DWORD scorebytesread;
unsigned long int hiscore = 0;
HANDLE hFile = CreateFile(TEXT("HiScore.dat"), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
if(hFile== INVALID_HANDLE_VALUE)
{
hiscore = 0;
return false;
}
if(!ReadFile(hFile, &storescore, 5, &scorebytesread, NULL))
{
CloseHandle(hFile);
return false;
}
ReadFile(hFile, &storescore, 5, &scorebytesread, NULL);
hiscore = atoi(storescore);
CloseHandle(hFile);
return hiscore;
}
.dat I/O
ok i think these functions are right for reading a 6 string intager from file then converting it into an intager then returning that intager
the other one is for writing a spacific variable to that same file via the scorestore buffer
I just want to see if these are right so that i can eliminate them on my list of errors because somthing is wrong with the I\O
Please:
- Use C++ fstream or even C stdio rather than win32 stuff (Unless you REALLY have to)
- use char instead of CHAR, which looks strange, and I'm not sure what it is
- If file size and performance is a nonissue, use a text file - it's easier for everyone
Mark
- Use C++ fstream or even C stdio rather than win32 stuff (Unless you REALLY have to)
- use char instead of CHAR, which looks strange, and I'm not sure what it is
- If file size and performance is a nonissue, use a text file - it's easier for everyone
Mark
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement