Jump to content
  • Advertisement
Sign in to follow this  
Erondial

Binary File IO in C

This topic is 4571 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

long int filenamesize = strlen(filename);
FILE* filetemp = fopen(filename,"rb");
long int filesize = GetFileSize(filetemp);
long int resourcesize = GetFileSize(resourcefile);
char* buffer = (char*)malloc(filesize);
fread(buffer,1,filesize,filetemp);
Now for some reason, I get a blank buffer when I'm doing this. Anyone have any idea why? I'm trying to open a totally red (255,0,0) 196x196 bitmap, but the buffer's empty. Any idea why? EDIT: And the file is open, it gets the file size properly as something around 115000 bytes or something

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
My first instinct is that GetFileSize() is returning 0 or a negative value, so you're not actually reading anything in. Otherwise, it should work.

Share this post


Link to post
Share on other sites
Waiiiiiiiiiiiiiiit. Got it. GetFileSize seeks to the end of the file and doesn't reuturn the stream to it's previous position, so it was trying to read off the end of the file. My mistake.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!