By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,563 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,563 IT Pros & Developers. It's quick & easy.

deleting and sorting in files

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

thank you in advance,
vishnu
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 1 Dec 2003 09:30:14 -0800, vi*************@yahoo.com (vishnu mahendra) wrote:
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')
Nov 13 '05 #2

P: n/a
vi*************@yahoo.com (vishnu mahendra) writes:
Can any one please tell me how to delete a record in a binary file.


Did you read the C FAQ? This is answered by question 19.14.
--
"I've been on the wagon now for more than a decade. Not a single goto
in all that time. I just don't need them any more. I don't even use
break or continue now, except on social occasions of course. And I
don't get carried away." --Richard Heathfield
Nov 13 '05 #3

P: n/a
vishnu mahendra wrote:

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.

--
Er*********@sun.com
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.