Thread: Deleting Record in Binary File without Temporary File

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    There is no standard way for you to make an existing file one record shorter.

    There are various OS specific options though.
    TRUNCATE(2) Linux Programmer's Manual TRUNCATE(2)

    NAME
    truncate, ftruncate - truncate a file to a specified length

    SYNOPSIS
    #include <unistd.h>
    #include <sys/types.h>

    int truncate(const char *path, off_t length);
    int ftruncate(int fd, off_t length);
    Binary files are often easiest to use if you have say
    - a specific record value that indicates that a record has been deleted (as phantomotap suggests).
    - a separate (and much shorter) index file containing a list of which records are valid, and which are deleted.

    Adding a record becomes easier, as it's just a matter of locating a vacant slot in your data 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.

  2. #2
    Registered User
    Join Date
    Aug 2019
    Location
    inside a singularity
    Posts
    308
    There is no standard way for you to make an existing file one record shorter.

    There are various OS specific options though.

    TRUNCATE(2) Linux Programmer's Manual TRUNCATE(2)

    NAME
    truncate, ftruncate - truncate a file to a specified length

    SYNOPSIS
    #include <unistd.h>
    #include <sys/types.h>

    int truncate(const char *path, off_t length);
    int ftruncate(int fd, off_t length);



    Oh. The assignment I got is to be done on TurboCrap and so I wouldn't be able to use <unistd.h>. I'll read more about truncate and try another version of my code on C::B

    - a specific record value that indicates that a record has been deleted (as phantomotap suggests).
    I'll use a "-1 \0" as an identifier for a deleted record and add a condition in "Display Records" to not display any records with "-1 \0"

    - a separate (and much shorter) index file containing a list of which records are valid, and which are deleted.
    This seems interesting. I'll implement this in C::B as a side project. Thanks for the idea!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. delete record from random access binary file
    By jack jordan in forum C Programming
    Replies: 1
    Last Post: 11-06-2017, 02:08 PM
  2. Binary file - delete record issue
    By ulti-killer in forum C Programming
    Replies: 1
    Last Post: 12-03-2012, 11:29 AM
  3. Deleting Text File Record
    By 01010011 in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2009, 02:46 PM
  4. Deleting / Changing a record in a text file
    By clearrtc in forum C Programming
    Replies: 9
    Last Post: 08-21-2006, 12:09 AM
  5. Deleting a Record from an input file
    By goron350 in forum C++ Programming
    Replies: 5
    Last Post: 06-15-2005, 03:40 PM

Tags for this Thread