<span style= "FONT-SIZE:18PX;" > #include <stdio.h> #include <string.h> #include <stdlib.h> #include <malloc.h> #include <conio.h> #define LEN sizeof (struct AB) #define ZIP 7#define PHONE 7#define MAX 100struct ab{char Name[10];char addr[1 0];char Zip[zip];char phone[phone];struct ab *next;}; struct AB *head;void search (struct ab *head), struct AB *add (struct ab *head), struct AB *del (struct ab *head), void Alter (ST Ruct ab *head); void print (struct ab *head); void Thefirst (); int n;</span>
<span style= "FONT-SIZE:18PX;" > #include "head.h" void Main () {n=0;head= (struct AB *) malloc (LEN); Thefirst ();} void Thefirst () {char c;system ("CLS");p UTS ("**************************************");p UTS (" contacts ");p UTS (" 1, Query ");p UTS (" 2, add ");p UTS (" 3, delete ");p UTS (" 4, modify ");p UTS (" 5, display ") ;p UTS (" 6, Return ");p UTS ("**************************************"); C=getch (); System ("CLS"); switch (c) { Case ' 1 ': Search (head), Break;case ' 2 ': Head=add (head); Thefirst (); Break;case ' 3 ': Head=del (head); Thefirst (); break; Case ' 4 ': Alter (head), break;case ' 5 ':p rint (head), break;case ' 6 ':p rintf ("BYE bye!\n");} </span>
<span style= "FONT-SIZE:18PX;" > #include "head.h" void search (struct ab *head) {char str[10];struct ab *p;p=head;printf ("Please input the name you want T o search!\n "); scanf ("%s ", str), if (p==null) {printf (" Please input the information first!press any key to thefirst \ n "); Getch (); Thefirst ();} System ("CLS"), for (;p &&strcmp (str,p->name);p =p->next), if (p) printf ("%10s\n%10s\n%10s\n%10s\n", p- >name,p->addr,p->zip,p->phone) elseprintf ("There is no information on the people you want!\n"); Getch (); Thefirst ();} </span>
<span style= "FONT-SIZE:18PX;" > #include "head.h" struct AB *add (struct ab *head) {struct AB *p1,*p2,*p3;char c[10];p rintf ("Please input the name!\n"); scanf ("%s", c);p 1=head;if (n==0) {strcpy (p1->name,c);p rintf ("Please input the address!\n"); scanf ("%s", p1->addr );p rintf ("Please input the zip!\n"), scanf ("%s", P1->zip);p rintf ("Please input the phone!\n"); scanf ("%s",p1-> Phone);p rintf ("%s\n", P1->phone);p 1->next=null;n++;} else{p3= (struct AB *) malloc (LEN); strcpy (p3->name,c);p rintf ("Please input the address!\n"); scanf ("%s", p3->addr );p rintf ("Please input the zip!\n"), scanf ("%s", P3->zip);p rintf ("Please input the phone!\n"); scanf ("%s",p3-> phone); if (strcmp (c,p1->name) <0) {head=p3;p3->next=p1;} Else{for (;p 1&&strcmp (c,p1->name) >0;p2=p1,p1=p1->next); if (p1==null) {P2->next=p3;p3->next =null;} ELSE{P2->NEXT=P3;P3->NEXT=P1;} n++;}} return head;} </span>
<span style= "FONT-SIZE:18PX;" > #include "head.h" struct AB *del (struct ab *head) {struct AB *p1,*p2;char c[10];p 1=head;printf ("Please input the name yo U want to delete\n "), scanf ("%s ", c), for (;p 1&&strcmp (c,p1->name);p 2=p1,p1=p1->next), if (p1==null) { printf ("Not find!press any key to thefirst \ n"); Getch ();} else if (p1==head) Head=p1->next;elsep2->next=p1->next;return head;} </span>
<span style= "FONT-SIZE:18PX;" > #include "head.h" void alter (struct AB *head) {char str[10];struct ab *p;p=head;printf ("Please input the name of you want to Search!\n "), scanf ("%s ", str), for (;p &&strcmp (str,p->name);p =p->next), if (p) {printf (" Address!\n "), scanf ("%s ", p->addr);p rintf (" Please input the zip!\n "), scanf ("%s ", P->zip);p rintf (" please input The phone!\n "); scanf ("%s ", P->phone);} else {printf ("not find!press any key to thefirst \ n"); Getch ();} Thefirst ();} </span>
<span style= "FONT-SIZE:18PX;" > #include "head.h" void print (struct ab *head) {struct AB *p;for (p=head;p;p=p->next) {printf ("%10s%10s%10s%10s\n" , P->name,p->addr,p->zip,p->phone);} Getch (); Thefirst ();} </span>
C Language Implementation Address Book