Use a linked list to implement address book and language learning address book
The main function of this program is to add, delete, search, insert, and display contact information.
(Call the linked list operation interface, please refer to: http://blog.csdn.net/qlx846852708/article/details/43482497)
Here is the detailed implementation process of the linked list operation interface that has been implemented and tested !!!
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include "addressBookList. h"
/* Display all information of the linked list */
Void chainlist_all (chainListType * head)
{
ChainListType * phead;
DATATYPE_T data;
Phead = head;
While (phead)
{
Data = phead-> data;
Printf ("name: % s, address: % s, telephone: % s \ n", data. key, data. add, data. telephone );
Phead = phead-> next;
}
Return;
}
/* Add a contact */
ChainListType * add_contact (chainListType * head)
{
DATATYPE_T contactInfo;
Printf ("please input contact information \ n ");
Scanf ("% s", contactInfo. key, contactInfo. add, contactInfo. telephone );
Return chainlist_add_end (head, contactInfo );
}
/* Search for contacts by keyword */
Int find_contact (chainListType * head)
{
Char key [15];
ChainListType * node = NULL;
Printf ("please input find key \ n ");
Scanf ("% s", key );
Node = chainlist_find (head, key );
If (node! = NULL)
{
Printf ("find info name: % s, address: % s, telephone: % s \ n", node-> data. key, node-> data. add, node-> data. telephone );
}
Else
{
Printf ("the key can't find !!! \ N ");
}
Return 0;
}
/* Delete a contact by keyword */
ChainListType * delete_contact (chainListType * head)
{
Char key [15];
ChainListType * phead = NULL;
Printf ("please input delete key \ n ");
Scanf ("% s", key );
Phead = chainlist_delete (head, key );
If (phead = NULL)
{
Printf ("delete after the list is NULL !!! \ N ");
Return NULL;
}
Return phead;
}
/* Insert contact information */
ChainListType * insert_contact (chainListType * head)
{
Char key [15];
DATATYPE_T insertData;
ChainListType * phead = NULL;
Printf ("please input insert key \ n ");
Scanf ("% s", key );
Printf ("please input insert contact information \ n ");
Scanf ("% s", insertData. key, insertData. add, insertData. telephone );
Phead = chainlist_insert (head, key, insertData );
Return phead;
}
/* Display all contact information */
Int show_contact (chainListType * head)
{
If (head = NULL)
{
Printf ("the list is NULL \ n ");
Return-1;
}
Chainlist_all (head );
Return 0;
}
Int menu ()
{
Printf ("********************** \ n ");
Printf ("1.add a contact \ n ");
Printf ("2. find a contact \ n ");
Printf ("3. delete a contact \ n ");
Printf ("4. insert a contact \ n ");
Printf ("5. show a contact \ n ");
Printf ("0. quit ");
Printf ("\ n ");
Printf ("********************** \ n ");
}
Int main ()
{
Int opt = 0;
ChainListType * head = NULL;
Do
{
Printf ("\ n ");
Printf ("please select option! \ N ");
Menu ();
Scanf ("% d", & opt );
Printf ("you select for % d \ n", opt );
Switch (opt)
{
Case 1:
Head = add_contact (head );
Break;
Case 2:
Find_contact (head );
Break;
Case 3:
Head = delete_contact (head );
Break;
Case 4:
Head = insert_contact (head );
Break;
Case 5:
Show_contact (head );
Break;
Case 0:
Return 0;
Default:
Printf ("unknow select \ n ");
Break;
}
} While (opt! = 0 );
Return 0;
}
Zookeeper