初学者 第一次写通讯录,写到头皮发麻。
灵活运用指针函数,返回值为指针
注意使用二级指针操作头指针head
注意del函数的判断条件
切记不骄不躁!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#define LEN sizeof(struct information)
//定义结构体
typedef struct information
{
char name[20];
char id[20];
char phone[20];
char home[20];
struct information *next;
}INFO;
//主菜单函数
void face()
{
printf("******address list*****\n");
printf("1:show all information\n");
printf("2:add information\n");
printf("3:delete information\n");
printf("4:modify information\n");
printf("5:search information\n");
printf("0:quit\n");
printf("***********************\n");
}
//显示所有联系人
INFO *print(INFO *head)
{
INFO *p;
p = head;
//system("clear");
if(head != NULL)
{
printf("***********************\n");
printf("members are as follow!\n");
while(p != NULL)
{
printf("name:%s\t",p->name);
printf("id:%s\t",p->id);
printf("phone:%s\t",p->phone);
printf("home:%s\n",p->home);
p = p->next;
}
}
else
{
printf("***********************\n");
printf("address_list is none!\n");
}
return head;
}
//增加联系人函数
INFO *add(INFO *head)
{
INFO *new_node = (INFO*)malloc(LEN);
printf("***********************\n");
printf("please input name!\n"