Thread: Phone book

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    5

    Phone book

    I'm working on a small phone book program. When a new entry is added to the phone book old entries should reorder themselves in the array alphabetically. For example, if the array contains:
    Anna
    Fred
    Jeff
    and I'm trying to add Bob, Fred and Jeff should be pushed down. I was thinking of using strncmp() to determine the numerical value of each entry. But I'm not sure where I'd go beyond there.

    PS. The same thing should happen when an entry is deleted from the phone book.

    Thanks in advance

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What you would need is a sorted list. I don't know if std::set is such a one? Others can probably tell you more.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Yes, objects stored in a set container are automatically ordered by default according to the less-than operator for whatever type (can be overridden and should be for complex/aggregate types) is stored within the container. Objects inserted into or deleted from the container will preserve that ordering.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Emulator
    Join Date
    Feb 2008
    Posts
    43
    First you have a multidimmensional array. An array in an array. An array of words with an array of letters. We get the first letter of all arrays and they arrange themselves alphabetically for we convert all them to numbers (typecasting). They replace each other endlessly until it all goes lowest to greatest. I admit this is very unclear and is easier said than done.
    Hand over your source code, and nobody gets hurt.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a phone book program
    By mackieinva in forum C Programming
    Replies: 2
    Last Post: 09-19-2007, 06:31 AM
  2. Phone Book
    By FerrariF12000 in forum C Programming
    Replies: 7
    Last Post: 12-10-2003, 12:07 AM
  3. phone book directory 2
    By arangawawa in forum C Programming
    Replies: 4
    Last Post: 08-01-2003, 05:32 PM
  4. Books on C and C++
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-28-2002, 04:18 PM
  5. Phone Class
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 03-30-2002, 07:42 AM