Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

.dat I/O

This topic is 5415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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;
    
} 

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!