473,507 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File I/O - Delete Record

Hi,

This is about File I/O Operation.

I want to delete a record from a file, let say FileA. Any one has any good
and efficient example/approach?
void DeleteRecord(int LineNum)
{
// open FileA
// open tmpFile
// copy all the contents in FileA except on LineNum to tmpFile
// re-copy tmpFile to FileA
}
Nov 14 '05 #1
5 3263

"Magix" <ma***@asia.com> wrote in message
news:41**********@news.tm.net.my...
Hi,

This is about File I/O Operation.

I want to delete a record from a file, let say FileA. Any one has any good
and efficient example/approach?
Hmmm... I'm quite sure this was a newsgroup on 'C' just a minute ago. So
unless you got a C-related problem with your implementation, the post is
off-topic.

<OT>
Google "Indexed Sequential Access Method" (ISAM).
</OT>
void DeleteRecord(int LineNum)
{
// open FileA
// open tmpFile
// copy all the contents in FileA except on LineNum to tmpFile
// re-copy tmpFile to FileA
}


That would give you rather a lot of overhead when deleting a number of
lines/records.
Nov 14 '05 #2
"Magix" <ma***@asia.com> wrote:
I want to delete a record from a file, let say FileA. Any one has any good
and efficient example/approach?


<http://www.eskimo.com/~scs/C-faq/q19.14.html>

Richard
Nov 14 '05 #3

"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:41**************@news.individual.net...
"Magix" <ma***@asia.com> wrote:
I want to delete a record from a file, let say FileA. Any one has any good and efficient example/approach?
<http://www.eskimo.com/~scs/C-faq/q19.14.html>


Wow...

Missed that one.
Richard

Nov 14 '05 #4
On Wed, 12 Jan 2005 12:01:18 +0100, dandelion wrote:

"Magix" <ma***@asia.com> wrote in message
news:41**********@news.tm.net.my...
Hi,

This is about File I/O Operation.

I want to delete a record from a file, let say FileA. Any one has any good
and efficient example/approach?
Hmmm... I'm quite sure this was a newsgroup on 'C' just a minute ago. So
unless you got a C-related problem with your implementation, the post is
off-topic.


It isn't unreasonable to consider this from a C perspecive i.e. given the
file handling tools that C provides.
<OT>
Google "Indexed Sequential Access Method" (ISAM). </OT>


That's one alternative. It does depend on the file in question being ISAM
compatible, and you having an ISAM library available
void DeleteRecord(int LineNum)
{
// open FileA
// open tmpFile
// copy all the contents in FileA except on LineNum to tmpFile //
re-copy tmpFile to FileA
This is a possible approach, and reasonable for small files. I'd just
observe here that standard C defines a rename() function which could be
used for the last step.
}
}

That would give you rather a lot of overhead when deleting a number of
lines/records.


You can still delete a number of lines/records in one pass, just avoid
copying all of the lines in question.

Lawrence
Nov 14 '05 #5

"Lawrence Kirby" <lk****@netactive.co.uk> wrote in message
news:pa****************************@netactive.co.u k...
On Wed, 12 Jan 2005 12:01:18 +0100, dandelion wrote:

"Magix" <ma***@asia.com> wrote in message
news:41**********@news.tm.net.my...
Hi,

This is about File I/O Operation.

I want to delete a record from a file, let say FileA. Any one has any good and efficient example/approach?


Hmmm... I'm quite sure this was a newsgroup on 'C' just a minute ago. So
unless you got a C-related problem with your implementation, the post is
off-topic.


It isn't unreasonable to consider this from a C perspecive i.e. given the
file handling tools that C provides.
<OT>
Google "Indexed Sequential Access Method" (ISAM). </OT>


That's one alternative. It does depend on the file in question being ISAM
compatible, and you having an ISAM library available


It also presents a not-too-difficult mechanism to "save up" deletions and
handle them in one go. This dramatically improving response times.
void DeleteRecord(int LineNum)
{
// open FileA
// open tmpFile
// copy all the contents in FileA except on LineNum to tmpFile //
re-copy tmpFile to FileA
This is a possible approach, and reasonable for small files. I'd just
observe here that standard C defines a rename() function which could be
used for the last step.
}
}

That would give you rather a lot of overhead when deleting a number of
lines/records.


You can still delete a number of lines/records in one pass, just avoid
copying all of the lines in question.


Yes. But that is not in the algorithm as presented.

Not too difficult to implement, though. Downside is, you have to have a
"list" of records to delete. If the program is driven by a UI, this will
most likely not be the case and response times will be dramatic.

Anyway. I think the OP would be alot better off using a
(commercial/opensource/whatever) standard solution than trying to reinvent
the wheel.
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4262
by: Ruben | last post by:
Hello. I am trying to read a small text file using the readline statement. I can only read the first 2 records from the file. It stops at the blank lines or at lines with only spaces. I have a...
3
2692
by: Abhas | last post by:
> > Hi, this is Abhas, > > I had made a video library program in C++, but was facing a problem. > > After entering 12 movies, i cannot enter any more movies. > > Something gibberish comes instead....
1
4439
by: Someonekicked | last post by:
I have a binary file, and I need to delete a specific number of characters in it. The file contains records, each record has a specific length. So the way I wanna handle deleting is that I will...
3
3307
by: Earl Teigrob | last post by:
I am considering writing a Class that Selects, Adds, Updates and Deletes Nodes in an XML File but do not what to reinvent the wheel. (See XML file below) That data format would emulate records...
8
4033
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: ...
3
3955
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to...
4
7833
by: Susan Bricker | last post by:
I have a command button on a form that is supposed to Delete the record being displayed. The record is displayed one to a form. The form is not a Pop-Up nor is it Modal. Tracing the btnDelete...
11
2669
by: Steve Hoyer | last post by:
I am trying to deploy my first asp.net app to our webserver (2K server, IIS 5) My start page comes up and you can get to the subsequent pages that are tied into our sql server (2K). Each page...
2
4581
by: richardkreidl | last post by:
I want to be able to delete and search for elements in a XML file, I'm using the code below for adding elements which works great: Public Sub cmdAddElement_Click(ByVal sender As System.Object,...
5
3168
by: prakashwadhwani | last post by:
The Delete Event/Proc & "Save_Fields_In_Form_Header" Event/Proc in my form were working perfectly. However, after I added a call to the "Save_Fields_In_Form_Header" Event/Proc in the...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.