Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Writing a huge structure data to file

Writing a huge structure data to file

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manoharbalu
    wrote on last edited by
    #1

    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.

    L J L 3 Replies Last reply
    0
    • M manoharbalu

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Without seeing your code it is impossible to guess what you are doing wrong. How are you writing it, with a single fwrite call, or separate calls for each structure item?

      1 Reply Last reply
      0
      • M manoharbalu

        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.

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • M manoharbalu

          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.

          L Offline
          L Offline
          leon de boer
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups