473,663 Members | 2,726 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(in t 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 3284

"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(in t 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.ind ividual.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(in t 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****@netacti ve.co.uk> wrote in message
news:pa******** *************** *****@netactive .co.uk...
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(in t 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
4272
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 while statement checking for an empty string "" which I understand represents an EOF in Python. The text file has some blank lines with spaces and other with blanks. Thanks a lot.
3
2704
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. > > Can somebody please tell whats wrong?? > > This is the code : : #include<fstream.h> #include<conio.h>
1
4448
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 overwrite the record I want to delete with the last record in the file, then actually delete that last record in the file. the problem Im having is how to delete that last record in the file. Suppose each record is of length 43, then I have...
3
3321
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 in a Database Table with a Primary Key for each Record (see xml sample below) and a flat file structure. I would use a class to manipulate this type of data structure extensivly if I had one. Does anyone know of such an animal?
8
4051
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: DoCmd.SetWarnings False DoCmd.RunCommand acCmdDeleteRecord DoCmd.SetWarnings True End If ExitHere: Me!SubName.SetFocus
3
3964
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 delete a record in this subform. When I switched modal off and tried to delete a record from the list, I deleted a record on another form (below the popup form).
4
7841
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 event routine shows that AllowDeletions is TRUE. When the Delete button is clicked (without TRACE ON), I get a 'beep', the recordselector (vertical bar on left of form) gets dark in color, but the record is not deleted. Also, there is no error...
11
2685
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 has a datagrid that loads up just fine, but when I click on any link that updates the page, i.e. a column header to sort the database, it returns a 404 error. Any ideas why it works the for the inital load and not on a postback?
2
4597
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, ByVal e As System.EventArgs) Handles cmdAddElement.Click Dim doc As New XmlDocument doc.Load("c:UMZ.xml") Dim root As XmlNode = doc.DocumentElement
5
3175
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 "Current" Event of my form, and I now try to Delete a record, I get ... Run-Time Error 3218 - Could not Update; Currently Locked. My Access application then effectively freezes forcing me to shut Access down & re-start. The record DOES get deleted...
0
8345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8858
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8548
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8634
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7371
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4182
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4349
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1757
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.