Writing a huge structure data to file
-
I am using huge structure template and size is around 100kb with various member variables like char array, int, long and short. I am writing this entire structure using fwrite. But when I retreive the structure data from file using fread, some of the structure members especially long variable shows incorrect value. Kindly suggest me if writing a full structure is wrong or how to work around.
-
I am using huge structure template and size is around 100kb with various member variables like char array, int, long and short. I am writing this entire structure using fwrite. But when I retreive the structure data from file using fread, some of the structure members especially long variable shows incorrect value. Kindly suggest me if writing a full structure is wrong or how to work around.
-
I am using huge structure template and size is around 100kb with various member variables like char array, int, long and short. I am writing this entire structure using fwrite. But when I retreive the structure data from file using fread, some of the structure members especially long variable shows incorrect value. Kindly suggest me if writing a full structure is wrong or how to work around.
manoharbalu wrote:
Kindly suggest me if writing a full structure is wrong
As described probably it is incorrect. Even the design is suspect. Such a large collection must be divisible and as such it should be programmed that way. Note of course that this doesn't mean it cannot be handled as a serialized data stream. That is in fact what all files on disk are exactly. Other than that it is likely that you have a bug in your code that reads or writes the data. Probably you have a size wrong. If the process was broken into smaller pieces (as I said above) then you could individually test each of those and thus insure that the entire thing was valid.
-
I am using huge structure template and size is around 100kb with various member variables like char array, int, long and short. I am writing this entire structure using fwrite. But when I retreive the structure data from file using fread, some of the structure members especially long variable shows incorrect value. Kindly suggest me if writing a full structure is wrong or how to work around.
Have you made sure you open the file for write in binary mode.
FILE * binfile = fopen("somefilename.bin", "wb"); //Open writable bin file
You open it with just "w" command and it's in text mode some of the raw struct characters will be translated to tabs, CR, LF etc.
In vino veritas