deleting and sorting in files

  • Thread starter vishnu mahendra
  • Start date
V

vishnu mahendra

hello to all,
Can any one please tell me how to delete a record in a binary file.

thank you in advance,
vishnu
 
E

Eric Sosman

vishnu said:
hello to all,
Can any one please tell me how to delete a record in a binary file.

There is no one single way to do this. Some possibilities
(some are suitable only for restricted notions of "a record"):

- Overwrite the record's bytes with a pattern that the
rest of the software package will ignore. For example,
the rest of the software might recognize an all-zero
telephone number as meaning "no data in this record."

- Overwrite the record's bytes with a copy of the very
last record in the file, and rewrite the file's header
(or similar self-description) to indicate that the file
is one record shorter than it used to be.

- Copy the entire file to a new file, but omit the record
in question when you come to it. Then delete the old
file and rename the new file.

.... and there are many other variations.
 
L

Lew Pitcher

hello to all,
Can any one please tell me how to delete a record in a binary file.

Sorry, but the C language doesn't have a standard method of deleting records
from a file. It doesn't even recognize that a file can have records.

Your best bet is a read/copy loop: read a "record" from your input file, if not
deletable, write the "record" to the output file, loop until end-of-file.

--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employers')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,303
Messages
2,571,557
Members
48,359
Latest member
Raqib_121635
Top