请高手帮一下,看看我变得这个原程序有什么问题,为什么按5删除就显示错误
手机名片管理系统概述:
通过计算机对数据文件的存储和读取,实现名片的输入,输出,查找,修改,删除,分类存储等功能。最大可以管理300张名片。
要求:
命令行界面
有输入功能
有删除条目功能
有输出功能
有显示列表功能
有根据某一特点的查找功能
有分类存储功能
//这样就可以了哦
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <windows.h>
#define null 0
#define Length sizeof(struct Person)
int Count=0;
struct Person
{
char name[81];
int age;
char sex[81];
char telephone[81];
struct Person *next;
};
struct Person *head;
struct Person *tail;
void Welcome()
{
printf("\t欢迎来到您的手机通讯录\n");
printf("1.添加联系人\n");
printf("2.显示通讯录\n");
printf("3.查询联系人\n");
printf("4.修改联系人\n");
printf("5.删除联系人\n");
printf("6.清空通讯录\n");
printf("7.退出通讯录\n");
printf("请选择: ");
}
void Input(struct Person *p)
{
p->next=null;
printf("请输入联系人的相关信息:\n");
_flushall();
printf("姓名:");
gets(p->name);
printf("年龄:");
scanf("%d",&p->age);
getchar();
printf("性别:");
gets(p->sex);
printf("电话:");
gets(p->telephone);
}
void Print(struct Person *p)
{
printf("\n姓名:%s",p->name);
printf("\n年龄:%d",p->age);
printf("\n性别:%s",p->sex);
printf("\n电话:%s\n",p->telephone);
}
struct Person* Find(char name[81])
{
struct Person *p=head;
while(p!=null&&strcmp(p->name,name)!=0)
{
p=p->next;
}
return p;
}
struct Person* FindFront(char name[81])
{
struct Person *p=head;
while(p!=null&&strcmp(p->next->name,name)!=0)
{
p=p->next;
}
return p;
}
void Search()
{
char name[81];
struct Person *p;
printf("请输入联系人姓名:");
getchar();
gets(name);
p=Find(name);
if(p)
Print(p);
else
printf("查无此人!\n");
}
void Show()
{
struct Person *p=head;
printf("一共有%d位联系人:\n",Count);
while(p!=null)
{
Print(p);
p=p->next;
}
}
void PushBack()
{
struct Person *p=(struct Person*)malloc(Length);
Input(p);
tail->next=p;
tail=p;
p->next=0;
}
void FirstPush()
{
struct Person *p=(struct Person*)malloc(Length);
Input(p);
head=p;
tail=p;
}
void Add()
{
if(Count==0)
FirstPush();
else
PushBack();
++Count;
}
void Modify()
{
char name[81];
struct Person *p;
printf("请输入要修改的联系人姓名:");
getchar();
gets(name);
p=Find(name);
if(p)
{
Input(p);
printf("恭喜你,修改成功!\n");
}
else
printf("查无此人!\n");
}
void PopFront()
{
struct Person *p=head;
head=p->next;
free(p);
--Count;
}
void Delete()
{
char name[81];
struct Person *pfront;
struct Person *p;
printf("请输入要删除的联系人姓名:");
getchar();
gets(name);
pfront=FindFront(name);
p=Find(name);
if(p)
{
pfront->next=p->next;
free(p);
--Count;
printf("恭喜你,你已经成功删除该联系人\n");
}
else
printf("查无此人!\n");
}
void Clear()
{
while(Count)
PopFront();
printf("恭喜你,你已经清空通讯录\n");
}
int Select(int selection)
{
switch(selection)
{
case 1:Add();return 0;
case 2:Show();return 0;
case 3:Search();return 0;
case 4:Modify();return 0;
case 5:Delete();return 0;
case 6:Clear();return 0;
default:printf("Bye-Bye! See you again!\n");system("pause");return 1;
}
}
void Start()
{
int selection;
while(1)
{
system("color 07");
Welcome();
scanf("%d",&selection);
if(Select(selection))
return;
system("pause");
system("cls");
}
}
int main()
{
Start();
return 0;
}
0