Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ankan666

file operation

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

Hi, i''m trying to make a MD3-load function, (MD3=quake3''s modelformat) and i''m trying to read in the whole file to a buffer, and then parse the buffer... i''m using this code FILE *f = fopen(filename,"r"); fseek(f, 0, SEEK_END); int filesize = ftell(f); fseek(f, 0, SEEK_SET) byte *buffer = new byte[filesize]; memset(buffer, 0, sizeof(buffer)); total_read = fread(buffer, filesize, 1, f); fclose(f); my problem is that fread() seems to only read about half the file which is totally unacceptable. if I try to do a fread(buffer, 1, filsize, f) instead, fread() returns 268, when it should return 9484 (which is the size of the file). can someone explain this?

Share this post


Link to post
Share on other sites
Advertisement
ok I found the problem...

fread() stops reading when it finds the byte (1A), because fread() thinks it''s a EOF-sign. How do I overcome this?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Could you give me a link where I can find some info about the MD3 format?!

Share this post


Link to post
Share on other sites
quote:
Original post by ankan666

ok I found the problem...

fread() stops reading when it finds the byte (1A), because fread() thinks it''s a EOF-sign. How do I overcome this?


Yes, you open the file as a text file (the default type). You should open it as a binary file i think. You should add a flag at the fopen() function but i don''t remember which one. Check the fopen() doc and see how you can open a binary file.

Don''t forget to tell us if it works, it''s always more pleasant to know our posts are useful.




Prosper / LOADED corporation

Share this post


Link to post
Share on other sites

  • 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!