Https://github.com/sunlitao one. Experiment 1 Address Book Management system
Contacts in Contacts contain the following information items: name, cell phone, office phone, home phone, e-mail address, city and province, work unit, home Address, Group category ( Relatives, colleagues, classmates, friends, others ) .
The main functions of the system include:
1. Enter the contact's information and request that you enter at least the data for each of the three contacts and pay attention to the diversity of the data.
2. Sort the contact information by name and store the post-order information in a text file.
3. Add a contact's information and add several contacts to the existing contacts file. Requirement: The name of the contact is still sorted and saved to the original file after it is added.
4. Delete the contact's information, enter a name, if there is information about the contact in the Address Book, delete the contact, otherwise output a hint, and prompt the user to choose whether to continue the delete operation.
5. Modify the contact information, enter a name, modify one of the contact's information according to the specific needs, save the modified information to the Address Book file again, and prompt the user to choose whether to continue the modification operation.
6. Query the address book according to different conditions, and output the information of the contact who satisfies the condition.
(1) search by name, including exact query ( Enter full name ), fuzzy query ( Enter last name ) ;
(2) Search by mobile phone number, enter all number or number segment (such as input ,133,139 , etc.);
(3) Search by group, enter category name, and output all contact information of the group.
7. output contact information, according to a certain format output information, to ensure that the information arranged neatly and beautifully.
The procedure is as follows:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct{
Char num[5];
Char name[9];
Char sex[3];
Char phone[13];
Char addr[31];
}datatype;
typedef struct node{
DataType data;
struct node * NEXT;
}listnode;
typedef listnode * LINKLIST;
Linklist head;
ListNode *p;
int Menu_select ();
Linklist createlist (void);
void Insertnode (linklist head,listnode *p);
ListNode * Listfind (linklist head);
void Delnode (linklist head);
void Printlist (linklist head);
int main ()
{
for (;;) {
Switch (Menu_select ())
{
Case 1:
printf ("***********************************\n");
printf ("* Establishment of *\n list");
printf ("***********************************\n");
Head=createlist ();
Break
Case 2:
printf ("***********************************\n");
printf ("* Add *\n for Communicator information");
printf ("***********************************\n");
printf ("Number (4) name (8) gender phone (11) address (+) \ n");
printf ("***********************************\n");
p= (ListNode *) malloc (sizeof (ListNode));
scanf ("%s%s%s%s%s", P->data.num,p->data.name,p->data.sex,
P->DATA.PHONE,P->DATA.ADDR);
Insertnode (HEAD,P);
Break
Case 3:
printf ("***********************************\n");
printf ("* Query *\n for Address Book Information");
printf ("***********************************\n");
P=listfind (head);
if (p!=null) {
printf ("Number name gender contact phone address \ n");
printf ("-------------------------------------\ n");
printf ("%s,%s,%s,%s,%s\n", P->data.num,p->data.name,p->data.sex,
P->DATA.PHONE,P->DATA.ADDR);
printf ("-------------------------------------\ n");
}
Else
printf ("Failed to find the!\n to inquire");
Break
Case 4:
printf ("***********************************\n");
printf ("* Deletion of directory information *\n");
printf ("***********************************\n");
Delnode (head);
Break
Case 5:
printf ("***********************************\n");
printf ("* Output *\n of the Contacts list");
printf ("***********************************\n");
Printlist (head);
Break
Case 0:
printf ("T-see! \ n ");
return 0;
}
}
}
int Menu_select ()
{
int SN;
printf ("Directory Management system \ n");
printf ("==============================\n");
printf ("1. The establishment of the contacts list \ n");
printf ("2. Insertion of Communicator nodes \ n");
printf ("3. Communication node query \ n");
printf ("4. Communication node deletion \ n");
printf ("5. Output \ n" of the contacts list);
printf ("0. Exit management system \ n");
printf ("==============================\n");
printf ("Please select 0-5:");
for (;;)
{
scanf ("%d", &SN);
if (sn<0 | | sn>5)
printf ("\n\t output error, re-election 0-5:");
Else
Break
}
return SN;
}
Linklist createlist (void)
{
Linklist head= (ListNode *) malloc (sizeof (ListNode));
ListNode *p,*rear;
int flag=0;
Rear=head;
while (flag==0)
{p= (ListNode *) malloc (sizeof (ListNode));
printf ("Number (4) name (8) gender phone (11) address (+) \ n");
printf ("---------------------------------------------------\ n");
scanf ("%s%s%s%s%s", P->data.num,p->data.name,p->data.sex,
P->DATA.PHONE,P->DATA.ADDR);
rear->next=p;
Rear=p;
printf ("Do you want to finish building the table?" (1/0): ");
scanf ("%d", &flag);
}
rear->next=null;
return head;
}
void Insertnode (linklist head,listnode *p)
{
ListNode *p1,*p2;
P1=head;
p2=p1->next;
while (P2!=null && strcmp (p2->data.num,p->data.num) <0)
{
P1=P2;
p2=p2->next;
}
p1->next=p;
p->next=p2;
}
ListNode * Listfind (linklist head)
{
ListNode *p;
Char num[5];
Char name[9];
int XZ;
printf ("=====================\n");
printf ("1. Search by number \ n");
printf ("2. Search by name \ n");
printf ("=====================\n");
printf ("Please select:");
p=head->next;
scanf ("%d", &XZ);
if (xz==1) {
printf ("Please enter the number of the person to be queried:");
scanf ("%s", num);
while (P && strcmp (p->data.num,num) <0)
p=p->next;
if (P==null | | strcmp (p->data.num,num) >0)
P=null;
}
Else
if (xz==2) {
printf ("Please enter the name of the person to be queried:");
scanf ("%s", name);
while (P && strcmp (p->data.name,name)!=0)
p=p->next;
}
return p;
}
void Delnode (linklist head)
{
int JX;
ListNode *p,*q;
P=listfind (head);
if (p==null) {
printf ("Did not find the Communicator!\n to delete");
Return
}
printf ("Do you really want to delete this node?" ( 1/0): ");
scanf ("%d", &JX);
if (jx==1)
{
Q=head;
while (Q!=null && q->next!=p)
{q=q->next;}
p=q->next;
q->next=p->next;
Free (p);
Return
printf ("The Communicator has been deleted!\n");
}
}
void Printlist (linklist head)
{
ListNode *p;
p=head->next;
printf ("Number name gender contact phone address \ n");
printf ("---------------------------------------\ n");
while (P!=null)
{
printf ("%s,%s,%s,%s,%s\n", P->data.num,p->data.name,p->data.sex,
P->DATA.PHONE,P->DATA.ADDR);
printf ("----------------------------------------------------\ n");
p=p->next;
}
}
Establishment of a communication table
Insertion of junction of two communicator
Add a Communicator message at a time
Query of three communication nodes
① Search by name Zhang San
Removal of four Communicator nodes
Output of the five contacts list
Vi. exit of the management system
Summary and experience
In this program, understand often get a problem is to first analyze the overall framework and divided into small pieces, pay attention to the selection and comparison of pointers and linked list which is better, make the program more simple, more efficient, more to understand the functions have what function, how to use is very important, There are a lot of things to learn from the program as well.
Problems occurred during the design process, when the same serial number is entered without repeating the prompt, improve
1. Personal Project Individual Project