MAIN.C
#include"STDIO.H"
#include"CONIO.H"
#include"STDLIB.H"
#include"DEF_TYPE.H"
int main(void)
{
struct tel_node *head;
char key_select;
char name[20];
extern void Nemu_Display();
extern struct tel_node *Open_Node();
extern struct tel_node *Creat_Node();
extern struct tel_node *Add_Node(struct tel_node *head);
extern struct tel_node *Dec_Node(struct tel_node *head,char *name);
extern struct tel_node *Clean_Node(struct tel_node *head);
extern void Find_Node(struct tel_node *head,char *name);
extern void Node_Display(struct tel_node *head);
extern void Save_Node(struct tel_node *head);
while(key_select!=0x1B)
{
Nemu_Display();
key_select=getch();
switch(key_select)
{
case '1':head=Open_Node();getch();break;
case '2':system("cls");printf("请输入要查找的联系人姓名:%s",name);Find_Node(head,name);getch();break;
case '3':head=Add_Node(head);Node_Display(head);getch();break;
case '4':system("cls");printf("请输入要删除的联系人姓名:%s",name);head=Dec_Node(head,name);Node_Display(head);getch();break;
case '5':head=Clean_Node(head);break;
case '6':Save_Node(head);puts("数据已保存!");getch();break;
default:break;
}
}
return(0);
}
INTER_FACE.C
#include"STDIO.H"
#include"CONIO.H"
#include"STDLIB.H"
#include"DATA.H"
void Nemu_Display()
{
char i,j;
system("cls");
puts("\n\n\n\n");
for(i=0;i<2;i++)
{
printf("\t\t\t%s\t%s\t%s\n",nemu[i*3],nemu[i*3+1],nemu[i*3+2]);
puts("\t\t\t------\t------\t------");
puts("\n\n");
}
}
OPEN_NODE.C
#include"STDIO.H"
#include"STDLIB.H"
#include"STRING.H"
#include"DEF_TYPE.H"
struct tel_node *Open_Node()
{
FILE *fp_tel_node;
struct tel_node *head;
struct tel_node *read;
struct tel_node *tail,*p_new;
char temp;
extern struct tel_node *Creat_Node();
extern void Node_Display(struct tel_node *head);
system("cls");
fp_tel_node=fopen("E:\\电话号码本.txt","rt");
if(fp_tel_node)
{
while(feof(fp_tel_node)==0)
{
fscanf(fp_tel_node,"%s\t%s\n",read->name,read->tel_code);
printf("%s\t%s\n\n",read->name,read->tel_code);
p_new=(struct tel_node *)malloc(sizeof(struct tel_node));
strcpy(p_new->name,read->name);
strcpy(p_new->tel_code,read->tel_code);
p_new->next=NULL;
if(head==NULL)
{
head=p_new;
}
else
{
tail->next=p_new;
}
tail=p_new;
}
fclose(fp_tel_node);
}
else
{
head=Creat_Node();
Node_Display(head);
}
return(head);
}
SAVE_NODE.C
#include"STDIO.H"
#include"STDLIB.H"
#include"DEF_TYPE.H"
void Save_Node(struct tel_node *head)
{
FILE *fp_tel_node;
struct tel_node *write;
fp_tel_node=fopen("E:\\电话号码本.txt","wt");
if(head)
{
write=head;
while(write)
{
fprintf(fp_tel_node,"%s\t%s\n",write->name,write->tel_code);
write=write->next;
}
}
system("cls");
fclose(fp_tel_node);
}
CRAET_NODE.C
#include"STDIO.H"
#include"CONIO.H"
#include"STDLIB.H"
#include"STRING.H"
#include"DEF_TYPE.H"
struct tel_node *Creat_Node()
{
struct tel_node *head;
struct tel_node *tail,*p_new;
char name[20];
char tel_code[11];
head=NULL;
printf("姓名\t电话号码:");
scanf("%s%s",name,tel_code);
putch('\n');
while(strcmp(name,"0")!=0&&strcmp(tel_code,"0")!=0)
{
p_new=(struct tel_node *)malloc(sizeof(struct tel_node));
strcpy(p_new->name,name);
strcpy(p_new->tel_code,tel_code);
p_new->next=NULL;
if(head==NULL)
{
head=p_new;
}
else
{
tail->next=p_new;
}
tail=p_new;
printf("姓名\t电话号码:");
scanf("%s%s",name,tel_code);
putch('\n');
}
return(head);
}
ADD_NODE.C
#include"STDIO.H"
#include"CONIO.H"
#include"STDLIB.H"
#include"DEF_TYPE.H"
struct tel_node *Add_Node(struct tel_node *head)
{
struct tel_node *tail,*p_new;
char name[20];
char tel_code[11];
system("cls");
printf("姓名\t电话号码:");
scanf("%s%s",name,tel_code);
putch('\n');
p_new=(struct tel_node *)malloc(sizeof(struct tel_node));
strcpy(p_new->name,name);
strcpy(p_new->tel_code,tel_code);
p_new->next=NULL;
if(head==NULL)
{
head=p_new;
}
else
{
tail=head;
while(tail->next!=NULL)
{
tail=tail->next;
}
tail->next=p_new;
tail=p_new;
}
return(head);
}
DEC_NODE.C
#include"STDIO.H"
#include"STDLIB.H"
#include"STRING.H"
#include"DEF_TYPE.H"
struct tel_node *Dec_Node(struct node *head,char *name)
{
struct tel_node *dec,*front,*back;
if(head!=NULL)
{
dec=head;
while(strcmp(dec->name,name)!=0)
{
front=dec;
dec=dec->next;
}
back=dec->next;
front->next=back;
free(dec);
}
return(head);
}
CLEAR_NODE.C
#include"STDIO.H"
#include"STDLIB.H"
#include"DEF_TYPE.H"
struct tel_node *Clean_Node(struct tel_node *head)
{
struct tel_node *del,*next;
system("cls");
del=head;
while(del)
{
next=del->next;
free(del);
del=next;
}
head=NULL;
return(head);
}
FIND_NODE.C
#include"STDIO.H"
#include"CONIO.H"
#include"STDLIB.H"
#include"STRING.H"
#include"DEF_TYPE.H"
void Find_Node(struct tel_node *head,char *name)
{
struct tel_node *find;
system("cls");
if(head==NULL)
{
puts("没有联系人!\n");
}
else
{
find=head;
while(strcmp(find->name,name)!=0&&find!=NULL)
{
find=find->next;
}
if(find!=NULL)
{
printf("%s\t%s\n",find->name,find->tel_code);
}
else
{
puts("没有此联系人!\n");
}
}
}
NODE_DISPLAY.C
#include"STDIO.H"
#include"CONIO.H"
#include"STDLIB.H"
#include"DEF_TYPE.H"
void Node_Display(struct tel_node *head)
{
struct tel_node *dis;
system("cls");
if(head==NULL)
{
puts("没有联系人!\n");
}
else
{
dis=head;
while(dis)
{
printf("%s\t%s\n\n",dis->name,dis->tel_code);
dis=dis->next;
}
}
}
DATA.H
#ifndef _DATA_H
#define _DATA_H
extern char *nemu[6];
#endif
DATA.C
#include"DATA.H"
char *nemu[6]=
{
"1.打开","2.查找","3.添加","4.删除","5.清除","6.保存"
};
DEF_TYPE.H
#ifndef _DEF_TYPE_H
#define _DEF_TYPE_H
struct tel_node
{
char name[20];
char tel_code[11];
struct tel_node *next;
};
#endif
总共13个文件