Home > Back-end >  Unable to return header
Unable to return header

Time:12-16

Unable to return header





#include
#include
#include
Struct per/* define the type of structure */{
Long int num.
Char name [20].
Char tel [12].
Char mail [30].
Char add [50];

Long int mnum;
Char id [18];
Struct per * next;
};
Struct per * jianli ();/* * statement to establish contacts function/
Void shuchu (struct per * head);/* * statement output contacts function/
Struct per * tianjia (struct per * head);/* * statement add contact function/
Struct per * shanchu (struct per * head);/* declare the function delete contacts */
Struct per * chazhao (struct per * head);/* statement search contacts */function
Struct per * head=NULL;
Int main () {/* */
main functionInt the select;
Printf (" \ n \ t * * * * * * * * * * * * * * * * * welcome to personal contacts management system * * * * * * * * * * * * * * * * * * \ n ");
/* */master menu printf (" \ n \ t -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- & gt;> 1: make a general letter to record & lt; <-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");
Printf (" \ n \ t -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- & gt;> 2: lose out on letter record & lt; <-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");
Printf (" \ n \ t -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- & gt;> 3: add add touch person & lt; <-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");
Printf (" \ n \ t -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- & gt;> 4: delete in addition to touch people & lt; <-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");
Printf (" \ n \ t -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- & gt;> 5: looking for touch people & lt; <-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");
Printf (" \ n \ t -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- & gt;> 0: back out of the system & lt; <-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");

Printf (" \ n \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ n \ t please select (0-5) : ");
The scanf (" % d ", & amp; Select);
printf("\n");
The switch (select) {corresponding module functions/* */
Case 1:
The head=jianli ();
break;
Case 2:
Shuchu (head);
break;
Case 3:
The head=tianjia (head);
break;
Case 4:
The head=shanchu (head);
break;
Case 5:
The head=chazhao (head);
break;
Case 0:
break;
Default:
Printf (" you input is wrong, please input again (0-5) : \ n ");

}
While (select!=0);
}


/* * establish contacts function/
Struct per * jianli () {/* create a linked list, and returns the pointer meter */
Struct per * head;/* * header/
Struct per * p1;/* */new node
Struct per * (p2);/* */footer node
Long int num1.
Char name1 [20].
Char tel1 [12].
Char mail1 [30].
Char add1 [50].
Long int mnum1;
Char id1 [18].
The head=NULL;/* no any node, header to empty */

Printf (" please enter the contact number, name, telephone, id number, email, address and zip code (end) separated by a space, use 0 \ n ");
The scanf (" % d ", & amp; Num1);
While (num1!=0) {/* assume num=0 means input end */

The scanf (" % s % s % s % d % s % s ", name1, tel1, id1, mail1, add1, & amp; Mnum1);/* */read in the first contact information
P1=(struct) per * malloc (sizeof (struct per));/* create a new node */
P1 - & gt; Num=num1;/* into contact information */
Strcpy (p1 - & gt; The name, name1);
Strcpy (p1 - & gt; Tel, tel1);
Strcpy (p1 - & gt; Id, id1);
Strcpy (p1 - & gt; Mail, mail1);
Strcpy (p1 - & gt; Add, add1);
P1 - & gt; Mnum=mnum1;
P1 - & gt; Next=NULL;/* the next field is empty, said the end node */
If (head==NULL)
The head=p1;/* header is the first new node */
The else
The p2 - & gt; Next=p;/* the footer of the next node is a new node */
P1 p2=;/* new nodes become footer */
The scanf (" % d ", & amp; Num1);
}
Return the head;/* return a pointer to header */
}
/* */output contacts function
Void shuchu (struct per * head) {
Struct per * p;
Int n=0;/* statistical number of nodes that link number */
Printf (" \ n \ t * * * * * * * * * * * * * * * * * * * on * * * * * * * recorded letter * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ n % % % - 12-5 s s - 12-19 s % s % s % - 9-7 s % s \ n ", "number", "name", "phone number", "id", "email", "address", "zip code");
If (a head!=NULL) {
For (p=head; p!=NULL; P=p - & gt; Next) {/* if reach the end node exit circulation, or continue to */
Printf (" % % % - 12-5 d s - 12-19 s % s % s % - 9-7 d % s \ n ", p - & gt; Num, p - & gt; The name, p - & gt; Tel, p - & gt; Id, p - & gt; Mail, p - & gt; Add, p - & gt; Mnum);
n++;
}
Printf (" number of contacts: % d \ n \ n ", n);
} the else
Printf (" \ n I'm sorry, no contact in the contacts! \n\n");
}
/* */add contact function
Struct per * tianjia (struct per * head) {
Struct per * p;
Struct per * p1;
Struct per * (p2);
The p2=head;
P=(struct) per * malloc (sizeof (struct per));/* new node p */
Printf (" please enter to add a contact number, name, telephone, id number, email, address, zip code: \ n ");
The scanf (" % d % s % s % s % d % s % s ", & amp; p-> Num, p - & gt; The name, p - & gt; Tel, p - & gt; Id, p - & gt; Mail, p - & gt; Add, & amp; p-> Mnum);
Printf (" add contact % s success! \ n ", p - & gt; Name);
If (head==NULL) {
The head=p;
p-> Next=NULL;
} else {
While ((p - & gt; Num> The p2 - & gt; Num) & amp; & (p2 - & gt; Next!=NULL) {/* * find add position/
P1=p2;
The p2=p2 - & gt; next;
}
If (p - & gt; Num<=p2 - & gt; Num) {/* arrange since the childhood, added to the table within */
If (p2==head)
{
The head=p;
p-> Next=p2;
} else {
P1 - & gt; Next=p;
p-> Next=p2;
}
} else {/* added to the footer */
The p2 - & gt; Next=p;
p-> Next=NULL;
}
}
Return (the head);
}
/* */delete contacts function
Struct per * shanchu (struct per * head) {
Struct per * (p2);
Struct per * p1;
Int num1, n;
Printf (" please enter to delete contact number: ");/* according to the input information search contacts */
The scanf (" % d ", & amp; Num1);
If (head==NULL) {
Printf (" \ n the address book is empty \ n \ n ");
Return (the head);
}
The p2=head;
While (num1!=p2 - & gt; Num & amp; & The p2 - & gt; Next!=NULL) {
P1=p2;
The p2=p2 - & gt; next;
}
If (num1==p2 - & gt; Num) {
Printf (" \ n success query to the contacts! \n");
Printf (" \ n % % % - 12-5 s s - 12-19 s % s % s % - 9-7 s % s \ n ", "number", "name", "phone number", "id", "email", "address", "zip code");
Printf (" % % % - 12-5 d s - 12-19 s % s % s % - 9-7 s % d ", p2 - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related