关于用链表做的简单信息管理系统出现的问题。
#include"stdio.h"#include"string.h"
#include"stdlib.h"
typedef struct STU
{
char name[15];
char qq[13];
char phone[13];
struct STU *next;
} NODE;
int i;
NODE *head = NULL;
void input(int N);
void output();
void research();
void insert();
void del();
void add();
void destory();
int main()
{
int m;
static int N;
printf("请输入人数\n");
scanf("%d", &N);
while (1)
{
printf("---------------欢迎使用-------------\n");
printf("| 1,录入信息 |\n");
printf("| 2,输出信息 |\n");
printf("| 3,查找信息 |\n");
printf("| 4,修改信息 |\n");
printf("| 5,增加信息 |\n");
printf("| 6,删除信息 |\n");
printf("| 7.清空信息 |\n");
printf("------------------------------------\n");
printf("请选择\n");
scanf("%d", &m);
switch (m)
{
case 1:
input(N);
break;
case 2:
output();
break;
case 3:
research();
break;
case 4:
insert();
break;
case 5:
add();
break;
case 6:
del();
break;
case 7:
destory();
break;
}
}
}
void input(int N)
{
NODE *p, *tail;
p = (NODE *) malloc(sizeof(NODE));
printf("请输入第1位学生姓名qq及电话:\n");
scanf("%s%s%s", p->name, p->qq, p->phone);
p->next = NULL;
head = p;
tail = p;
for (i = 1; i < N; i++)
{
p = (NODE *) malloc(sizeof(NODE));
printf("请输入第%d位学生姓名qq及手机号:\n", i + 1);
scanf("%s%s%s", p->name, p->qq, p->phone);
tail->next = p;
p->next = NULL;
tail = p;
}
return head;
}
void output()
{
NODE *p;
p = head;
if (p == NULL)
printf("无记录\n");
else
{
while (p != NULL)
{
printf("姓名:%s qq:%s 电话:%s\n", p->name, p->qq, p->phone);
p = p->next;
}
}
}
void name_re()
{
char name_1[15];
NODE *p;
p = head;
if (p == NULL)
printf("无信息\n");
else
{
printf("输入姓名:\n");
scanf("%s", name_1);
while(p!=NULL)
{
if (strcmp(p->name, name_1) == 0)
{
printf("姓名:%s qq:%s 电话:%s\n", p->name, p->qq,
p->phone);
break;
}
p = p->next;
}
}
}
void qq_re()
{
char qq_1[13];
NODE *p;
p = head;
if (p == NULL)
printf("无信息\n");
else
{
printf("输入qq:\n");
scanf("%s", qq_1);
while(p!=NULL)
{
if (strcmp(p->qq, qq_1) == 0)
{
printf("姓名:%s qq:%s 电话:%s\n", p->name, p->qq, p->phone);
break;
}
p = p->next;
}
}
}
void phone_re()
{
char phone_1[15];
NODE *p;
p = head;
if (p == NULL)
printf("无信息\n");
else
{
printf("输入电话:\n");
scanf("%s", phone_1);
while(p!=NULL)
{
if (strcmp(p->phone, phone_1) == 0)
{
printf("姓名:%s qq:%s 电话:%s\n", p->name, p->qq, p->phone);
break;
}
p = p->next;
}
}
}
void research(int N)
{
int n;
printf("-------------查找系统-----------------\n");
printf(" 1.姓名查找 \n");
printf(" 2.qq查找 \n");
printf(" 3.电话查找 \n");
printf("--------------------------------------\n");
printf("请输入查找方式\n");
scanf("%d", &n);
switch (n)
{
case 1:
name_re();
break;
case 2:
qq_re();
break;
case 3:
phone_re();
break;
default:
printf("输入错误\n");
}
}
void insert()
{
char name_2[15];
NODE *p, *p1;
p = head;
p1 = head;
printf("输入需要修改的姓名\n");
scanf("%s", name_2);
while(p!=NULL)
{
if (strcmp(p->name, name_2) == 0)
{
printf("查找成功,请输入信息修改:\n");
scanf("%s%s%s", p->name, p->qq, p->phone);
break;
}
p = p->next;
}
}
void add()
{
NODE *p, *p1;
p = head;
int b;
if (p == NULL)
printf("请先录入信息\n");
else
{
printf("输入要增加的人数:\n");
scanf("%d", &b);
while (p->next != NULL)
{
p = p->next;
}
for (i = 1; i <= b; i++)
{
p1 = (NODE *) malloc(sizeof(NODE));
printf("输入增加的第%d位学生姓名,qq及电话:\n", i);
scanf("%s%s%s", p1->name, p1->qq, p1->phone);
p->next = p1;
p1->next = NULL;
p = p1;
}
}
}
void del()
{
char name_3[15];
NODE *p, *p1;
p = head;
p1 = head;
printf("输入需要删除的姓名\n");
scanf("%s", name_3);
while(p!=NULL)
{
if (strcmp(p->name, name_3) == 0)
{
printf("删除成功\n");
break;
}
p1 = p;
p = p->next;
}
if (p == head)
{
head = p->next;
free(p);
}
else
{
p1->next = p->next;
free(p);
}
}
void destory()
{
NODE *p = head;
if (p = NULL)
printf("无记录清空\n");
else
{
while (p != NULL)
{
head= p->next;
free(p);
p=head;
}
}
}
这个是我用链表做的简单信息管理,但是有两个函数功能模块实现不了,。一个是增加信息,一个是清空信息。。哪里错了。。。?怎么改??