大概的就是以下这个程序,只是个别的需要根据你的具体要求自己改改
#include
#include
#define max 50
struct date
{int month;
int year;
};
struct student
{ int number;
char name[10];
char sex[6];
struct date birthday;
char addr[30];
char tel[15];
char email[30];
int group;
}student[max];
typedef struct lnode
{ int number;
char name[10];
char sex[6];
struct date birthday;
char addr[30];
char tel[15];
char email[30];
int group;
struct lnode *next;
}listnode,*linklist;
linklist head=NULL,r=NULL;
listnode *s,*p0,*p1,*p2,*p3,*p4,*p5,*p6,*q0,*q1;
int i;
char name1[10],ch;
char str1[20];
FILE *fp; ;
void creat()
{ int j;
long k;
fp=fopen("Contacts.c","r+");
if(fp!=NULL)
{for(i=1;i
if(j==EOF)
return;
k=i-1;
fseek(fp,k*sizeof(struct student),0);
fread(&student[i],sizeof(struct student),1,fp);
s=(linklist)malloc(sizeof(listnode));
s->number=student[i].number;
strcpy(s->name,student[i].name);
strcpy(s->sex,student[i].sex);
s->birthday.year=student[i].birthday.year;
s->birthday.month=student[i].birthday.month;
strcpy(s->addr,student[i].addr);
strcpy(s->tel,student[i].tel);
strcpy(s->email,student[i].email);
s->group=student[i].group;
if(head==NULL)
head=s;
else
r->next=s;
r=s;}
}
else
{ fp=fopen("Contacts.c","w"); i=1;
}
}
void Input() /*此函数用于录入通讯录中学生的信息*/
{ s=(linklist)malloc(sizeof(listnode));
printf("\n\tplease input a list:");
printf("\n\n\t\tnumber:");
scanf("%d",&s->number);
printf("\n\t\tname:");
scanf("%s",s->name);
printf("\n\t\tsex:");
scanf("%s,s->sex");
printf("\n\t\tbirthday:");
scanf("%d.%d",&s->birthday.year,&s->birthday.month);
printf("\n\t\taddr:");
scanf("%s",s->addr);
printf("\n\t\ttel:");
scanf("%s",s->tel);
printf("\n\t\tE-mail:");
scanf("%s",s->email);
printf("\n\t\tgroup:");
scanf("%d",&s->group);
if(head==NULL)
head=s;
else
r->next=s;
r=s;
}
void Insert() /*此函数用于在通讯录中插入信息*/
{
q0=p6=head;
q1=(linklist)malloc(sizeof(listnode));
printf("\n\t\tplease input number:");
scanf("%s",&q1->number);
printf("\n\t\tplease input name:");
scanf("%s",q1->name);
printf("\n\t\tplease input sex:");
scanf("%s,q1->sex");
printf("\n\t\tplease input birthday:");
scanf("%d.%d",&q1->birthday.year,&q1->birthday.month);
printf("\n\t\tplease input addr:");
scanf("%s",q1->addr);
printf("\n\t\tplease input telphone:");
scanf("%s",q1->tel);
printf("\n\t\tplease input E-mail:");
scanf("%s",q1->email);
printf("\n\t\tplease inputgroup:");
scanf("%d",&q1->group);
do
{q0=q0->next;
p6=q0;}
while(q1->number>q0->number&&q1->number
p6=q0->next;
q0->next=q1;
p6=q1->next;
}
void Delete() /*此函数用于对通讯录中指定信息的删除*/
{ printf("\n\n\tplease input the student's name that you want to delete:");
gets(name1);
p4=head;
if(strcmp(p4->name,name1)==0)
{ p4=p4->next;
head=p4;
}
else
{ while(strcmp(p4->next->name,name1)!=0)
p4=p4->next;
p5=p4->next;
p4->next=p5->next;
free(p5);
}
printf("\n\n\t\t\tDelete Success!!!");
}
void Search() /*此函数用于对通讯录中指定信息的查询*/
{ printf("\n\n\tplease input the name:");
p0=head;
gets(name1);
while(strcmp(name1,p0->name)!=0&&p0!=NULL)
p0=p0->next;
if(p0==NULL)
printf("\n\n\tNo related records ");
else
{ printf("\n\tnumber:%d", p0->number);
printf("\n\tname:%s",p0->name);
printf("\n\tsex:%c",p0->sex);
printf("\n\tbirthday:%d.%d",p0->birthday.year,p0->birthday.year);
printf("\n\taddr:%s",p0->addr);
printf("\n\ttel:%s",p0->tel);
printf("\n\temail:%s",p0->email);
printf("\n\tgroup:%d",p0->group);
}
}
void Save()
{ int j;
fp=fopen("Contacts.c","w");
for(p2=head,j=0;p2!=NULL;j++,p2=p2->next)
{ student[j].number=p2->number;
strcpy(student[j].name,p2->name);
strcpy(student[j].sex,p2->sex);
student[j].birthday.year=p2->birthday.year;
student[j].birthday.month=p2->birthday.month;
strcpy(student[j].addr,p2->addr);
strcpy(student[j].tel,p2->tel);
strcpy(student[j].email,p2->email);
student[j].group=p2->group;
fwrite(&student[j],sizeof(struct student),1,fp);
}
}
void List() /*此函数用于对通讯信息进行浏览*/
{ p1=head;
while(p1!=NULL)
{ printf("\n\tnumber:%d", p1->number);
printf("\n\tname:%s",p1->name);
printf("\n\tsex:%c",p1->sex);
printf("\n\tbirthday:%d.%d",p1->birthday.year,p1->birthday.month);
printf("\n\taddr:%s",p1->addr);
printf("\n\ttel:%s",p1->tel);
printf("\n\temail:%s",p1->email);
printf("\n\tgroup:%d",p1->group);
p1=p1->next;
}
}
void main()
{ creat();
do
{printf("\n\t***************************************************************");
printf("\n\n\t Welcome to use this Contacts");
printf("\n\n\t Name: Fan Wenjiao--Class:Information 0701--No.071203104");
printf("\n\n\t***************************************************************");
printf("\n\n\t\t\t\tPlease make a choice :");
printf("\n\n\t\t\t\t1.Input a list");
printf("\n\n\t\t\t\t2.Delete a list ");
printf("\n\n\t\t\t\t3.Search a list");
printf("\n\n\t\t\t\t4.List all the list");
printf("\n\n\t\t\t\t5.Insert a list");
printf("\n\n\t\t\t\t6.Save and Quit");
printf("\n\n");
printf("\t\t\tPlease enter your choice :");
ch=getche();
switch(ch)
{ case '1': Input(); break;
case '2': Delete(); break;
case '3': Search(); break;
case '4': List(); break;
case '5': Insert(); break;
case '6': Save(); fclose(fp);
exit(0);
break;
default:
printf("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("\n\t Input error! \n");
printf("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
break;
}
}while(1);
}