Thread: deleting a structure from a file

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    41

    deleting a structure from a file


    In my delete func() I have noted where I need a func() to delete a selected structure. I have looked in every book I have and can't find an example to go by anywhere.

    Also, in my add_record func(), I need to be able to verify that the client_code has not already been used. Again, couldn't find any examples to help.

    Can anyone give me some examples to adapt to my own program?

    My code is attached.
    Thx.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Open a tmpfile and read the entire contents of your save file to it except the record you wish to delete. Then copy the tmpfile to the save file and the record will be deleted.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    41
    Originally posted by Prelude
    Open a tmpfile and read the entire contents of your save file to it except the record you wish to delete. Then copy the tmpfile to the save file and the record will be deleted.

    -Prelude

    How do I read all the records except the one I want to delete? This is the part that has me stuck. I know how to read all the files but how do I transfer them into a temp file and how do I make the program not read the record I want to delete? This is the code I don't know or understand.
    After I write the records to the temp file I overwrite the save file with the contents of temp. Correct?

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Just read from the save file and if the record isn't the one you want to delete, write it to the temporary file. If it is the one you want to delete you can just ignore it and read another. Then it's just a matter of copying all of the data in the temp file to the save file.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    41
    Originally posted by Prelude
    Just read from the save file and if the record isn't the one you want to delete, write it to the temporary file. If it is the one you want to delete you can just ignore it and read another. Then it's just a matter of copying all of the data in the temp file to the save file.

    -Prelude

    Still don't understand how to ignor the record to be deleted when reading. My func() call in the delete func() isn't working for some reason. Would you have a look at my tempfile func() and see if it's right. If not what chages should I make?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Deleting / Changing a record in a text file
    By clearrtc in forum C Programming
    Replies: 9
    Last Post: 08-21-2006, 12:09 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM