Thread: writing files

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    20
    Rep Power
    0
    When writing a file using fwrite, is there any way to append an already-existing file and have all new information added before any existing information?

    I have tried opening the file with "r+" as the mode, but it inserts the information as if you are typing with "insert" on your keyboard on.

    The only other thing I can think of is putting all existing information into a variable ($oldcontents, writing the new stuff using "w" as the mode and then adding the $oldcontents after... This way seems really dumb. Is there a better way?

    Thanks in advance

    ------------------
    ---------
    Lanny
    dtm
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    32
    Rep Power
    15
    Yup you can, use the switch a+ instead of r+

    This should let you append to end of the file. Good luck

    scoobydoo


    ------------------
    ------------------------
    web - <A HREF="http://www.pcmarket.com.au
    email" TARGET=_blank>http://www.pcmarket.com.au
    email</A> - scoobydoo@pcmarket.com.au
    ------------------------
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    20
    Rep Power
    0
    Problem is: I NEED to append the beginning.. I got it working with the afformentioned method, and I was able to streamline it a bit.. but there still has got to be a way to do it..

    ------------------
    ---------
    Lanny
    dtm
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    63
    Rep Power
    15
    use Fopen with A or A+

Similar Threads

  1. Writing to two *.csv files
    By CAR in forum Perl Programming
    Replies: 4
    Last Post: February 7th, 2004, 04:39 PM
  2. Writing to files with low level IO
    By Anjela in forum C Programming
    Replies: 1
    Last Post: January 20th, 2004, 07:22 PM
  3. reading and writing to files using structs
    By marco-marco in forum C Programming
    Replies: 1
    Last Post: December 25th, 2003, 12:17 PM
  4. problem writing files in script
    By RingWraith112 in forum Perl Programming
    Replies: 16
    Last Post: December 10th, 2003, 07:06 PM
  5. Writing wav files.
    By Scotsee in forum Multimedia Hardware
    Replies: 1
    Last Post: November 25th, 2003, 04:50 PM

IMN logo majestic logo threadwatch logo seochat tools logo