#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define OK 1
#define ERR 0
struct telbook()
{
char name[10];
char sex[2];
char adress[20];
char phonenumber[20];
struct telbook * next;//链表中的指针域
}
typedef struct telbook Node;
typedef struct telbook * Link;
void screen(); //菜单页面
void add_informantaion(); //添加信息
void create_new_link(); //创建带头指针的链表
void creat_new_node(); //创建结点
void judge_node(); //判断结点是否创建成功
Link insert_node_tail();//尾插
int main()
{
Link head;
int choice;
Link new_node;
create_new_link(&head);
while(1)
{
void screen();
printf(" 请从1到6中选择 \n");
scanf("%d",&choice);
switch(choice)
{
case 1:new_node = insert_node_tail(&head);//从尾部添加信息
add_informantaion(new_node);
getch();
break;
case 2:deleat_information();break;
case 3:change_information();break;
case 4:search_information();break;
case 6:list_information();break;
}
}
}
void screen()
{
printf("\n");
printf("\t\t*************************\n");
printf("\t\t* 通讯录菜单 *\n");
printf("\t\t* 1.添加信息 2.删除信息 *\n");
printf("\t\t* 3.修改信息 4.查找信息 *\n");
printf("\t\t* 5.保存 6.显示信息 *\n");
printf("\t\t* 退出前勿忘保存信息 *\n");
printf("\t\t*************************\n");
}
int judge_node(Link new_node)
{
if(new_node == NULL)
return ERR;
else
{
return OK;
}
}
void creat_new_node(Link *new_node)
{
do
{
new_node = (Link)malloc(sizeof(Node));
}while(judge_node(new_node) == ERR);
}
Link insert_node_tail(Link *head)
{
Link p;
p = *head;
while(p->next != NULL)
{
p = p->next;
}
p->next = new_node;
new_node->next = NULL;
}
void add_informantaion(Link new_node)
{
if(new_node == NULL)
{
printf("文件出现错误!即将返回\n");
return;
}
else
{
printf("\n输入姓名:");
scanf("%s",new_node->name);
printf("\n输入性别:");
scanf("%s"new_node->sex,);
printf("\n输入住址:");
scanf("%s"new_node->adress,);
printf("\n输入手机号码:");
scanf("%s",new_node->phonenumber);
}
}
void create_new_link(Link *head)
{
*head = (Link)malloc(sizeof(Node));
*head->next = *head;
}