File I/O - Delete Record

Discussion in 'C Programming' started by Magix, Jan 12, 2005.

  1. Magix

    Magix Guest

    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
    }
    Magix, Jan 12, 2005
    #1
    1. Advertising

  2. Magix

    dandelion Guest

    Re: [OT} File I/O - Delete Record

    "Magix" <> wrote in message
    news:41e4fcf9$...
    > 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.
    dandelion, Jan 12, 2005
    #2
    1. Advertising

  3. Magix

    Richard Bos Guest

    "Magix" <> 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
    Richard Bos, Jan 12, 2005
    #3
  4. Magix

    dandelion Guest

    "Richard Bos" <> wrote in message
    news:...
    > "Magix" <> 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
    dandelion, Jan 12, 2005
    #4
  5. Re: [OT} File I/O - Delete Record

    On Wed, 12 Jan 2005 12:01:18 +0100, dandelion wrote:

    >
    > "Magix" <> wrote in message
    > news:41e4fcf9$...
    >> 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
    Lawrence Kirby, Jan 13, 2005
    #5
  6. Magix

    dandelion Guest

    Re: [OT} File I/O - Delete Record

    "Lawrence Kirby" <> wrote in message
    news:p...
    > On Wed, 12 Jan 2005 12:01:18 +0100, dandelion wrote:
    >
    > >
    > > "Magix" <> wrote in message
    > > news:41e4fcf9$...
    > >> 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.
    dandelion, Jan 13, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SnVzdGlu?=

    Retrieving Record Key while creating the record.

    =?Utf-8?B?SnVzdGlu?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    618
    =?Utf-8?B?SnVzdGlu?=
    Oct 5, 2004
  2. André
    Replies:
    0
    Views:
    3,730
    André
    Jun 25, 2006
  3. MRW
    Replies:
    0
    Views:
    364
  4. THurkmans
    Replies:
    2
    Views:
    589
  5. Frits van Soldt

    How to insert a new record in detailsview when there are no record

    Frits van Soldt, Nov 16, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    720
    Frits van Soldt
    Nov 17, 2005
Loading...

Share This Page