Newbie - file i/o - I'm stuck

This is a discussion on Newbie - file i/o - I'm stuck within the C++ Programming forums, part of the General Programming Boards category; I am writing an array of 200 structures to a file, using frwite(&parts,sizeof (parts[0]),200,mydata); And I want to add to ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    1

    Newbie - file i/o - I'm stuck

    I am writing an array of 200 structures to a file, using
    frwite(&parts,sizeof (parts[0]),200,mydata);

    And I want to add to the end of the file, an integer that represents the amount of structures that contain data. How can I append the end of the file with this integer?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Same again, only different

    int myint = 200;
    fwrite(&myint,sizeof (myint),1,mydata);

    And this,
    frwite(&parts,sizeof (parts[0]),200,mydata);

    Should be this
    size_t nwrite = fwrite(parts,sizeof (parts[0]),200,mydata);
    1) Whilst its an array, parts and &parts are pretty much the same thing, but if you decide to dynamically allocate parts, then &parts would be very wrong
    2) check nwrite is 200 when you're done - if it isn't, then there's a problem writing the file

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Subtle(?) File I/O Problem
    By cecomp64 in forum C Programming
    Replies: 9
    Last Post: 07-16-2008, 11:39 AM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  4. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21