fucking fread( );

Started by
23 comments, last by Coluna 20 years, 9 months ago
Hi all; I''m having a very strange problem here... Here is some part of the code: ... profiles = new cPROFILE[number_of_profiles]; fread(profiles,1,sizeof(cPROFILE)*number_of_profiles,file); delete []profiles; ... Of course the line "delete []profiles;" is not there, but if I put it there it generates an Acess Violation Error...but when i take off the fread line, the error disappears. May it be a compiler error? Thanx all
Advertisement
i am almost pretty sure that your problem is in the call to fread try
fread (profiles,sizeof(cPROFILE),number_of_profiles,file);

hope that helps
Richard DickersonPikestriker Games "Kids you tried hard and failed miserably, lesson learned never try" - Homer Simpson
that only matters if EOF is reached, it shouldn''t make a difference
I''ve already tried using
fread(profiles,sizeof(cPROFILE),number_of_profiles,file);
but it didn''t solve my problem...
Are you storing any pointers in your profiles?
Michael Russell / QA Manager, Ritual EntertainmentI used to play SimCity on a 1:1 scale.
shouldnt it be:
fread(&profiles[0], sizeof(cPROFILE)*number_of_profiles, 1, file);
?
the only thing the two separate parameters do is if it reaches the end of file early, it reads the last whole structure before the end, but internally it just multiplies and reads. 1, x works fine, i use that all the time.
There is no pointers inside cPROFILE....and even using &profiles[0] (i used it before), it doesn''t work....when i inspect profiles (with quickwatch), it is allocated and with the correct values...so the fread() is working, as well as new()...i think i''ll try to copy this part in other application and see the results...
heh, well:

(profiles == &profiles[0]) == true

edit: forgot one 's'

[edited by - angry on July 5, 2003 2:16:25 AM]
Is that the exact code? Is there anything that goes on between the call to fread and the call to delete?

This topic is closed to new replies.

Advertisement