Thread: writing to end of file and reading in lines

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    32

    writing to end of file and reading in lines

    Hi...

    I'm kinda new to files on C... and i need to write a line to the end of the file each time I enter a funtion where each line would look like something like...
    Code:
    John entered 16
    I then also need to read line by line and display them....

    I'm writing to the file however i'm overwriting each time.... and reading only reads the only line I wrote :S

    Can some1 please tell me how I should be doing it?

    Thanks

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    When you open the file, it should be in append mode.

    http://www.cprogramming.com/tutorial/cfileio.html

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    32
    yep sorted it out.... actually i was calling another function before which was opening the file with O_TRUNC set hehe.....

    sorry for this stupid post :$ been awake for 30 hours+ :$ need some rest

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So get a good night's sleep already.

    Better than wasting time adding dumb bugs, then spending ages finding them again because you're too tired to notice what's going on.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. reading and writing to the end of a binary file
    By cloudy in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2005, 04:03 PM
  3. Replies: 6
    Last Post: 05-12-2005, 03:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM