Deleting text from a file???

This is a discussion on Deleting text from a file??? within the C Programming forums, part of the General Programming Boards category; I am making a program that keeps track of files. It does this by writing the name of the file ...

  1. #1
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127

    Deleting text from a file???

    I am making a program that keeps track of files. It does this by writing the name of the file into "filelist.txt" and then when I need to read the list I just scan the file and print out the names. My problem is that when I delete a file I also need to delete that listing in filelist.txt and I do not know how to do this. Any help would be appreciated. Thank you in advance.
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Read the whole thing, write it back out without whatever it is you don't want in it.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    How can I tell how many lines there are to read? I need to know how many lines I will be reading in so that I can make the array that they are stored in the right size.
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    > How can I tell how many lines there are to read?
    You only need to store 1 line

    - read a line in
    - do I want to keep it, if so write it to another file
    - repeat until end of file
    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.

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,156
    Quote Originally Posted by Salem
    > How can I tell how many lines there are to read?
    You only need to store 1 line

    - read a line in
    - do I want to keep it, if so write it to another file
    - repeat until end of file
    Then
    - delete the original file
    - rename the new file to the original name.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. 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
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM

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