By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,388 Members | 1,910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,388 IT Pros & Developers. It's quick & easy.

How to make a telephone directory????

P: 5
Can anyone help me in making this program?!...

I need to make a telephone directory using structure definition..

typedef struct AddressTag{
char surname[55];
char givenname[55];
char middleinitial[5];
char telnum[55];
struct PersonTag *next;
} AddType;

I need to have function for inserting, editing and deleting an entry.Entries should be inserted in alphabetical order according to the person's surname.It should also be able to save the entries to a file..
Sep 27 '06 #1
Share this Question
Share on Google+
5 Replies


100+
P: 293
D_C
typedef struct AddressTag{
char surname[55];
char givenname[55];
char middleinitial[5];
char telnum[55];
struct PersonTag *next;
} AddType;

Is this supposed to be a linked list? If your struct is AddressTag, what does PersonTag have to do with it? Where is that defined?

Until we know a PersonTag is, I'm not sure we can help you yet.
Sep 27 '06 #2

P: 5
typedef struct AddressTag{
char surname[55];
char givenname[55];
char middleinitial[5];
char telnum[55];
struct PersonTag *next;
} AddType;

Is this supposed to be a linked list? If your struct is AddressTag, what does PersonTag have to do with it? Where is that defined?

Until we know a PersonTag is, I'm not sure we can help you yet.
>
sori, I made a mistake. it should be struct AddressTag *next..
..pls help me..I really had a dificulty in doing this..
Sep 28 '06 #3

P: 5
How to make a telephone directory????
--------------------------------------------------------------------------------

Can anyone help me in making this program?!...

I need to make a telephone directory using structure definition..

typedef struct AddressTag{
char surname[55];
char givenname[55];
char middleinitial[5];
char telnum[55];
struct AddressTag *next;
} AddType;

I need to have function for inserting, editing and deleting an entry.Entries should be inserted in alphabetical order according to the person's surname.It should also be able to save the entries to a file...
Sep 28 '06 #4

P: 5
..please, I really need help..I have a hard time understanding this topic.. I don't know how to implement this. I need to make a program of an address book using this structure definition in C...

typedef struct AddTag{
char surname[100];
char firstname[100];
char address[100];
char tel_no[50];
struct AddTag *link;
} AddType;
AddType *List //list of entries
..I need to have a function for inserting entries in Alphabetical Order, editing entries, saving to a file and retrieving entries from a file...
..
Sep 28 '06 #5

Banfa
Expert Mod 5K+
P: 8,916
Please stop reposting the same topic.

You are trying to set up a linked list. In it's simplest form you start with a pointer to the first item. When you need to add a new item you allocate the memory (using malloc or new) fill in your structure and then make you new structure next pointer equal to the current first pointer and the then the first pointer point to the new structure.

Expand|Select|Wrap|Line Numbers
  1. AddType *pFirst = NULL;
  2.  
  3. void AddItem()
  4. {
  5.     AddType *pNewAdd = new AddType;
  6.  
  7.     pNewAdd->link = pFirst;
  8.     pFirst = pNewAdd;
  9. }
  10.  
You can list all the items by just taking apointer starting at the first item and itterating down the list until you get to NULL

Expand|Select|Wrap|Line Numbers
  1. void PrintList()
  2. {
  3.     AddType *pCurrent;
  4.  
  5.     for(pCurrent=pFirst; pCurrent != NULL; pCurrent=pCurrent->link)
  6.     {
  7.         // output data in pCurrent
  8.     }
  9. }
  10.  
Deleting at the begining of the list involves moving the first pointer onto the next item in the list and then delting the memory that it pointed to

Expand|Select|Wrap|Line Numbers
  1. void DeleteFirst()
  2. {
  3.     AddType *pDelete = pFirst;
  4.  
  5.     if (pDelete != NULL)
  6.     {
  7.         pFirst = pFirst->link;
  8.         delete pDelete;
  9.     }
  10. }
  11.  
Sep 28 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.