Delete a binary record

This is a discussion on Delete a binary record within the C Programming forums, part of the General Programming Boards category; How i'm going to delete a record form a binary file? Please give some idea on it.THANK!!...

  1. #1
    Unregistered
    Guest

    Delete a binary record

    How i'm going to delete a record form a binary file?
    Please give some idea on it.THANK!!

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    There are various ways..... one is to read all the data in, writing out only the records you want to a temporary file. When you're done reading, delete (or rename) the original file, and rename the temporary file to the main filename. If you don't want a temp file, read everything into memory instead.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    There's really no way to change just one record in a file, you have to read the entire file and write it back without the record you want, the same goes with insertion. The problem is that any method of modifying a record in place is inherently unsafe and error prone.

    -Prelude
    My best code is written with the delete key.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,496
    If your binary data has room for a flag which means 'deleted record', then you can just rewrite the record with this flag set.

    This prevents the need for rewriting the whole file each time, but you do need to occasionally compact the file by removing all the deleted records.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685

    short and sweet

    Pretty much the same way you do a text file. Its not really different at all.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with binary file c++
    By lucky_mutani in forum C++ Programming
    Replies: 4
    Last Post: 06-05-2009, 09:24 AM
  2. The best way to delete a record from a file?
    By salvadoravi in forum C Programming
    Replies: 25
    Last Post: 01-28-2008, 12:12 PM
  3. 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
  4. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 12:18 AM
  5. binary
    By webturtle0 in forum A Brief History of Cprogramming.com
    Replies: 52
    Last Post: 12-05-2002, 01:46 AM

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