Thread: Clearing lines form a text file

  1. #1
    Registered User
    Join Date
    Nov 2005

    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
    Registered User
    Join Date
    Aug 2005
    use a different openmode. "w" would clear the file.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    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.

    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:

    My website:
    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, 08: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