The best way to delete a record from a file?

This is a discussion on The best way to delete a record from a file? within the C Programming forums, part of the General Programming Boards category; Yeah I realized that afterwards, but dident bother posting about it. So, after all, I still don't get how 'moving' ...

  1. #16
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Yeah I realized that afterwards, but dident bother posting about it. So, after all, I still don't get how 'moving' is meant to work the same way as 'copying' here ???

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    Just copy and truncate the end of the file and you've basically "moved" the data. Or you can just zero it out. Either way.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Yeah, but then you have two copies and by truncating you just remove the copy you just made o_0

    The way I see it is that to physically 'move' the data you need to remove the space where the original data was stored at. The only way I know how to do this is by overwriting the rest of the file from the place where the data was removed.

  4. #19
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by mike_g View Post
    Yeah, but then you have two copies and by truncating you just remove the copy you just made o_0

    The way I see it is that to physically 'move' the data you need to remove the space where the original data was stored at. The only way I know how to do this is by overwriting the rest of the file from the place where the data was removed.
    If the old data is past the end of file and therefore not accessible, it is in essence, deleted.

  5. #20
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Yeah I get that part, but it does not explain the process of moving it.

  6. #21
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    On the contrary, it does.
    Let's say we have 5 records, 1, 2, 3, 4 and 5. We delete record 3. So we copy the from record 4 and 5 downwards, so we overwrite record 3. So we copy record 4 and 5 and it thus becomes:
    1, 2, 4, 5, 5. Then we truncate the end to remove the extra 5 and it becomes 1, 2, 4, 5. Makes sense?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Lol, well I knew that too! I just explained it as the only way i saw this being possible. With a large database thats getting updated all the time thats going to be a hell of a lot slower than just marking a character to signal an entry as deleted. Then you would only need to rewrite the data once in a while instead.

  8. #23
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    Indeed, and that's why the delete flag is preferable!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Who said they needed to be in order? Who said they were in order to start with?

  10. #25
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    None, but then again, no one said they do not need to.
    So it's just to pick an applicable solution.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    For most things in a computer: Move = Copy + Delete
    Unless you want to physically cut a piece of the hard drive surface away and glue it onto a new location on the platter; then it would truly be considered a Move.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. Update Record & Delete Record in File.
    By unsafe_pilot1 in forum C Programming
    Replies: 13
    Last Post: 05-18-2008, 07:22 AM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  4. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  5. how to delete or modify a record in a file?
    By danielhf in forum C++ Programming
    Replies: 2
    Last Post: 09-22-2003, 09:18 AM

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