Delete contact from phonebook

This is a discussion on Delete contact from phonebook within the C Programming forums, part of the General Programming Boards category; Hi there! I will get to the point. I have a list of contacts. I can delete the contact that ...

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    19

    Delete contact from phonebook

    Hi there!

    I will get to the point.

    I have a list of contacts.

    I can delete the contact that I want, I put all the fields in blank with a if but the position of the contact remains there.

    Code:
    if((strcmp(agenda[i].name, delete_name)) == 0){
              agenda[i].name[0] = '\0';
              agenda[i].phonenumber[0] = '\0';
              agenda[i].email[0] = '\0';
    break;
    }
    For example I have 10 contacts, 0-9 in my counter, and I delete the position 5 (the sixth contact), and after a list the contacts and the position remains there.

    I know how to solve the problem, but I don't know how to do it, for example by copying the last position to the position that was deleted and make "number_of_contacts--".

    Probably this is very easy but i'm having trouble with this
    Last edited by Gotze; 01-15-2012 at 05:25 AM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Think of it the other way around. Zero out empty records, set your print functions to NOT print or show zeroed out records, and have your program look for zeroed out records, to overwrite with new records being added.

    One thing you want to REALLY limit in your data, is unnecessary moving/shuffling. You can easily imagine that if you had a phonebook with 100,000 records in it, and people were being added and removed daily by the dozens, you'd have a heck of a mess with adding deleting records, and all the shuffling around that this would lead to.

    Truth is, you don't even want to sort your data - you build an index of the data that will display your data in sorted order, but you don't want to sort/resort, every time a record is added or subtracted.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to delete a contact in a phone book?
    By blogchama in forum C Programming
    Replies: 10
    Last Post: 01-25-2010, 11:37 AM
  2. how to contact these guys ?
    By black in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-08-2002, 07:15 PM
  3. how many of you contact your congressman?
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 05-24-2002, 11:33 AM
  4. don't contact me, people, i don't know!
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 02-05-2002, 06:06 AM
  5. Online contact!
    By CodeMonkey in forum Windows Programming
    Replies: 2
    Last Post: 11-19-2001, 01:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21