Clearing lines form a text file

This is a discussion on Clearing lines form a text file within the C Programming forums, part of the General Programming Boards category; I'm currently writing a program which writes some test to a text file, at the moment, everytime it'd run it ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    145

    Clearing lines form a text file

    I'm currently writing a program which writes some test to a text file, at the moment, everytime it'd run it just appends the output to the previous output. Insead of doing this I need to clear the old output, and replace it with my own.

    How could I go about clearing the contents of the text file?

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    use a different openmode. "w" would clear the file.
    Kurt

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    The term for the behaviour you're looking for is "truncuate". It sounds like you're currently using an append mode like "a". Try "w" as suggested.

    http://www.cppreference.com/stdio/fopen.html
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. Replies: 15
    Last Post: 10-31-2005, 07:29 AM
  4. Function is called and I am trying to open a file
    By tommy69 in forum C Programming
    Replies: 88
    Last Post: 05-06-2004, 08:33 AM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM

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