Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > File I/O - Delete Record

Reply
Thread Tools

File I/O - Delete Record

 
 
Magix
Guest
Posts: n/a
 
      01-12-2005
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
}


 
Reply With Quote
 
 
 
 
dandelion
Guest
Posts: n/a
 
      01-12-2005

"Magix" <(E-Mail Removed)> wrote in message
news:41e4fcf9$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      01-12-2005
"Magix" <(E-Mail Removed)> 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
 
Reply With Quote
 
dandelion
Guest
Posts: n/a
 
      01-12-2005

"Richard Bos" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Magix" <(E-Mail Removed)> 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



 
Reply With Quote
 
Lawrence Kirby
Guest
Posts: n/a
 
      01-13-2005
On Wed, 12 Jan 2005 12:01:18 +0100, dandelion wrote:

>
> "Magix" <(E-Mail Removed)> wrote in message
> news:41e4fcf9$(E-Mail Removed)...
>> 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
 
Reply With Quote
 
dandelion
Guest
Posts: n/a
 
      01-13-2005

"Lawrence Kirby" <(E-Mail Removed)> wrote in message
news(E-Mail Removed) k...
> On Wed, 12 Jan 2005 12:01:18 +0100, dandelion wrote:
>
> >
> > "Magix" <(E-Mail Removed)> wrote in message
> > news:41e4fcf9$(E-Mail Removed)...
> >> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating a Record using a current record MRW ASP .Net 0 02-11-2008 06:58 PM
IP Address, MX Record, A Record Question K.J. 44 Cisco 2 09-06-2006 05:14 PM
You cannot add or change a record because a related record is required in table 'lok" André ASP .Net 0 06-25-2006 01:30 PM
Retrieving Record Key while creating the record. =?Utf-8?B?SnVzdGlu?= ASP .Net 4 10-05-2004 08:11 PM
" Invalid Disk Table in Boot Record - Boot Record could not be repaired " reply@newsgroup.please Computer Support 2 12-01-2003 05:37 AM



Advertisments