Thread: Appending mid file

  1. #1
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507

    Appending mid file

    I haven't had to write out to files much...

    Right now i open a file and search for something then insert a string after something has been found. My problem is the file doesn't automatically shift to make room for this new text(my insertion erases the old contents). Is there a way to write in the middle of a file and have everything auto shift so that I dont have to copy everything from after where im about to write and re-write it?

    Thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    As soon as you figure out how to make a new piece of disk drive magically appear between those pieces of data, we'll get that in C.

    In other words, no.

  3. #3
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    I figured there may be some standard function option that could accomplish this for me, sorry. So the best(I guess only) way to do this is copy everything that im about to overwrite(even though this could eventually be huge), write my buffer, and then rewrite my copy buffer?

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Yes.
    Mainframe assembler programmer by trade. C coder when I can.

  5. #5
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    The two above posts are correct. What needs to happen is to read in your original file while writing out your file data to another file while appending your string when appropriate, then continue writing your original file data.

    When ever you need to merge two files together, there will be three files needed to get this accomplished, 2 for reading in data and a third for writing and or appending to an existing file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM