Thread: Manipulating Text File?

  1. #1
    Registered User Silverdream's Avatar
    Join Date
    Feb 2002
    Posts
    53

    Question Manipulating Text File?

    Hi,
    I am manipulating a text file and would like to know how can i delete a part of the file.

    The actual situation is i am creating an employee details database text file. I would like to delete the details of one employee by specifying the employee ID. How can i do this? Please help.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There a few schools of thought here:

    1) you can truncate the file at the point of deletion, and then, assuming you've read anything that you wanted to keep beyond that point, you then append that data back

    2) you can use some tag in the data when you write it, and use it to mean "deleted". Then, when writing new records, if you come across one that has the "deleted" tag, you can overwrite it.

    3) You can use the same method that you use to compact arrays:

    a->b->c->d

    deltee 'b' by doig:

    copy c over top of b (now it looks like: a->c->c->d)
    copy d back one place: (now it looks like: a->c->d->d)
    truncate the file after d. (now it looks like: a->c->d)

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. checking values in a text file
    By darfader in forum C Programming
    Replies: 2
    Last Post: 09-24-2003, 02:13 AM
  4. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM