分多个文件写通讯录

分多个文件写通讯录

一 address.h中的内容

分多个文件写通讯录
分多个文件写通讯录

二 main.c中的内容如下

分多个文件写通讯录
分多个文件写通讯录

三 address.c文件中的内容如下

#include"address.h"

void display(Linklist *L)
{
Linklist *p;
p = L->next;
printf(“no\tname\tnum\taddress\n”);
printf("==== \t====\t====\t====\n");
int count = 1;
while( p)
{
printf("%d\t%s\t%s\t%s\n",count,p->name,p->num,p->addr);
p = p->next;
count++;
}
}

void add(Linklist *L)
{
Linklist *p,*s;
p = L;
while(p->next)
{
p = p->next;
}
s = (LNode)malloc(sizeof(Linklist));
printf(“name:”);
scanf("%s",s->name);
printf(“num:”);
scanf("%s",s->num);
printf(“addr:”);
scanf("%s",s->addr);
s->next = NULL;
p->next = s;
}

void search(Linklist *L)
{
Linklist *p;
p = L;
int n;
puts(“search which?”);
scanf("%d",&n);
int i;
for(i = 1;i < n + 1;i++)
{
p = p->next;
}
if(p == NULL)
{
puts(“empty!”);
}
else
{
printf("%s\t",p->name);
printf("%s\t",p->num);
printf("%s\t",p->addr);
printf("\n");
}
}

void update(Linklist *L)
{
Linklist *p;
p = L;
int n;
puts(“update which?”);
scanf("%d",&n);
int i;
for(i = 1;i < n + 1;i++)
{
p = p->next;
}
if(p == NULL)
{
puts(“empty!”);
}
else
{
printf(“name:”);
scanf("%s",p->name);
printf(“num:”);
scanf("%s",p->num);
printf(“addr:”);
scanf("%s",p->addr);
}
}

void del(Linklist *L)
{
Linklist *p,*q;
p = L;
int n;
puts(“delete which?”);
scanf("%d",&n);
int i;
for(i = 1;i < n;i++)
{
p = p->next;
}
if(p == NULL)
{
puts(“empty!”);
}
else
{
q = p->next;
p->next = q->next;
free(q);
printf (“delete success!\n”);
}
}

int menu()
{
printf ("*******************************************************\n");
printf (" address book *\n");
printf (" \n");
printf (" 1)display *\n");
printf (" 2)update *\n");
printf (" 3)delete *\n");
printf (" 4)add *\n");
printf (" 5)search *\n");
printf (" 0)exit *\n");
printf ("\n");
printf ("\n\n");

}