Sign in to follow this  

Binary File IO in C

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

This topic is 4359 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this