writing to end of file and reading in lines

This is a discussion on writing to end of file and reading in lines within the C Programming forums, part of the General Programming Boards category; Hi... I'm kinda new to files on C... and i need to write a line to the end of the ...

  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,211
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 06: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, 01:46 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM

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