#include
#include
#include
#include
# define LEN sizeof (struct linkman)
Int len.
Typedef struct Linklist
{
Char num [9].
Char username [90].
Char sex [30].
Char phone [130].
Char addr [30].
Struct Linklist * next;
} Linklist;
Void menu ()
{
Printf (" \ t \ t | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the address book management system -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | \ n ");
Printf (" \ t \ t | [1] the establishment of the contacts list | \ n ");
Printf (" \ t \ t | [2] communicator nodes insertion | \ n ");
Printf (" \ t \ t | | [3] communication node of the query \ n ");
Printf (" \ t \ t | [4] communicator node delete | \ n ");
Printf (" \ t \ t | [5] the output of the contacts list | \ n ");
Printf (" \ t \ t | | [0] exit management system \ n ");
Printf (" \ t \ t | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - | \ n ");
Printf (" \ t \ \ t t enter an option (0 to 5) : ");
}
Linklist * creat ()
{
Linklist * head;
Var1 Linklist * and * var2;
Char numb [9].
Len=0;
Var1=(Linklist *) malloc (len);
Var2=var1;
Printf (" please input the current need to input the information! \n");
Printf (" end when the input q represents \ n ");
Printf (" please input sequence: \ n ");
Gets (numb);
If (STRCMP (numb, "q")!=0)
{
Strcpy (var1 - & gt; Num numb);
Printf (" please enter the contact name ");
Gets (var1 - & gt; The username);
Printf (" please enter the contact address ");
Gets (var1 - & gt; Addr);
Printf (" please enter the contact gender ");
Gets (var1 - & gt; Sex);
Printf (" please input contact phone ");
Gets (var1 - & gt; Phone);
The head=NULL;
While (1)
{
Len=len + 1;
If (len==1)
{
The head=var1;
}
The else
{
Var2 - & gt; Next=var1;
}
Var2=var1;
Printf (" please enter the sequence \ n ");
The scanf (" % s ", & amp; Numb);
If (STRCMP (numb, "q")==0)
{
break;
}
The else
{
Var1=(Linklist *) malloc (len);
Strcpy (var1 - & gt; Num numb);
Printf (" please enter the contact name \ n ");
The scanf (" % s ", var1 - & gt; The username);
Printf (" please enter the contact address \ n ");
The scanf (" % s ", var1 - & gt; Addr);
Printf (" please enter the contact gender \ n ");
The scanf (" % s ", var1 - & gt; Sex);
Printf (" please enter the contact phone \ n ");
The scanf (" % s ", var1 - & gt; Phone);
}
}
Var2 - & gt; Next=NULL;
}
}
Void Insert (Linklist * l)
{
Linklist * p * q * s;
P=q=l;
For (p; p!=NULL;)
{
Q=p;
p=p-> next;
}
S=(Linklist *) malloc (sizeof (Linklist));
S=p;
Printf (" please enter a number to insert \ n ");
Gets (s - & gt; Num);
Printf (" please enter to insert the names of the people \ n ");
Gets (s - & gt; The username);
Printf (" please enter to insert a person's sex \ n ");
Gets (s - & gt; Sex);
Printf (" please enter to insert phone \ n ");
Gets (s - & gt; Phone);
Printf (" please enter to insert the address of \ n ");
Gets (s - & gt; Addr);
}
Void Getelem (Linklist * l)
{
Var1 Linklist * and * var2;
Printf (" please enter a serial number to query the contact \ n ");
Char numb [9].
Gets (numb);
For (var1=var2=l; Var1!=NULL;)
{
If (STRCMP (var1 - & gt; Num, numb)==0)
{
Printf (" gender: name, serial number: % s % s % s telephone: % s address: % s ", var1 - & gt; Num, var1 - & gt; The username, var1 - & gt; Sex, var1 - & gt; Phone, var1 - & gt; Addr);
}
The else
{
Var2=var1;
Var1=var1 - & gt; next;
}
}
}
Void the Delete (Linklist * l)
{
Linklist * p, * q;
Char numb [9].
If (l - & gt; Next==NULL)
{
Printf (" your operating address book is empty \ n ");
}
Printf (" please input you want to delete the contact number \ n ");
Gets (numb);
For (p=q=l; p!=NULL;)
{
If (STRCMP (p - & gt; Num, numb)==0)
{
Q - & gt; next=p-> next;
Free (p);
P=q - & gt; next;
Printf (" the contact has been deleted! \n");
Q=p=l;
}
The else
{
Q=p;
p=p-> next;
}
}
Printf (" the contact you are looking for does not exist \ n ");
}
Void show (Linklist * l)
{
Linklist * p;
P=l;
If (p!=NULL)
{
Printf (" now the address book system records a total of % d: \ n ", len);
If (p!=NULL)
{
Do
{
Sequence: printf (" % s \ n name: % s \ n address: % s \ n tel: % s \ n gender: % s \ n ", p - & gt; Num, p - & gt; The username, p - & gt; Addr, p - & gt; Phone, p - & gt; Sex);
p=p-> next;
} while (p!=NULL);
}
}
The else
{
Printf (" address book is empty! \n");
}
}
Int main ()
{
Linklist * l=NULL;
int n;
While (1)
{
menu();
The scanf (" % d ", & amp; N);
The fflush (stdin);
The switch (n)
{
Case 1:
{
L=creat ();
Show (l);
}
break;
Case 2:
Insert (l);
break;
Case 3:
Getelem (l);
break;
Case 4:
Delete (l);
break;
Case 5:
Show (l);
break;
Case 0:
Printf (" exit system! \n");
break;
Default:
Printf (" you input a wrong option! \n");
break;
}
}
}
CodePudding user response:
After your so-called input address does not perform what meaning be?The input?
Does not perform after what do you mean?
I run your program, it is normal.
CodePudding user response:
The