file operation
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?
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?
fread() stops reading when it finds the byte (1A), because fread() thinks it''s a EOF-sign. How do I overcome this?
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement