给你一个管理系统,自己改改,这些系统都是大差不差的。这个是用链表写的,电话薄:
//日期:2013.7.8
//功能:电话薄
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#define max sizeof(phone_book)
typedef struct linkman
{
char name[10];
char number[15];
char team_name[10];
struct linkman * next;
}phone_book;
/*void init(phone_book *L)//初始化链表
{
L->next=NULL;
}*/
/*void paixu(phone_book * ph)
{
phone_book m;
phone_book *p,*t;
char ch;
p=ph->next;
t=p->next;
while(p!=NULL)
{
while(t!=NULL)
{
if(strcmp(p->name,t->name)>0)
{
strcpy (m.name,p->name);
strcpy (m.number,p->number);
strcpy (m.team_name,p->team_name);
strcpy (p->name,t->name);
strcpy (p->number,t->number);
strcpy (p->team_name,t->team_name);
strcpy (t->name,m.name);
strcpy (t->number,m.number);
strcpy (t->team_name,m.team_name);
}
t=t->next;
}
p=p->next;
t=p;
}
printf("排序成功!查看请输入 5 ");
ch=getch();
return;
}*/
void add(phone_book * ph)//添加函数
{
phone_book *h,*p,*t;
char add_name[10],add_number[15],add_team[10];
char ch,c;
system("cls");
printf("================添加联系人===============\n");
h=p=ph;
if(p->next==NULL)
{
t=(phone_book *)malloc(max);
printf("联系人姓名:");
scanf("%s",add_name);
printf("联系人号码:");
scanf("%s",add_number);
strcpy(t->name,add_name);
strcpy(t->number,add_number);
p->next=t;
t->next=NULL;
}
else if(p->next!=NULL)
{
t=(phone_book *)malloc(max);
printf("联系人姓名:");
scanf("%s",add_name);
while(p->next!=NULL)
{
if(strcmp(p->next->name,add_name)==0)
{
printf("姓名重复请重新输入\n");
printf("联系人姓名:");
scanf("%s",add_name);
}
p=p->next;
}
printf("联系人号码:");
scanf("%s",add_number);
strcpy(t->name,add_name);
strcpy(t->number,add_number);
t->next=p->next;
p->next=t;
p=t;
}
printf("是否要添加分组(Y/N):");
ch=getch();
if(ch=='Y'||ch=='y')
{
printf("\n请输入分组名:");
scanf("%s",add_team);
strcpy(t->team_name,add_team);
printf("信息输入成功");
c=getch();//用于控制回到主界面
return ;
}
else if(ch=='N'||ch=='n')
c=getchar();
return ;
}
phone_book * sele(phone_book * ph,char name[])//查找函数
{
phone_book *h;
phone_book *p;
char ch,c;
char sele_name[10];
h=ph->next;
p=ph->next;
strcpy(sele_name,name);
if(p==NULL)
{
printf("联系人为空,是否要输入联系人信息(Y/N):");
ch=getch();
if(ch=='Y'||ch=='y')
add(ph);
else if(ch=='N'||ch=='n')
{
c=getch();
return (NULL);
}
}
else
{
while(p!=NULL)
{
if(strcmp(p->name,sele_name)==0)
{
printf("姓名 号码 分组\n");
printf("%s %s %s",p->name,p->number,p->team_name);
c=getch();
return (p);
}
p=p->next;
}
p=ph->next;
while(p!=NULL)
{
if(strcmp(p->name,sele_name)!=0)
{
printf("该联系人不存在,或已删除");
c=getch();
return (p);
}
p=p->next;
}
}
return (p);
}
void dele(phone_book * ph)
{
phone_book *p,*t;
char dele_name[10];
char ch,c;
system("cls");
printf("=============删除联系人信息==============\n");
if(ph->next==NULL)
{
printf("联系人为空,是否要输入联系人信息(Y/N)\n");
ch=getchar();
if(ch=='Y'||ch=='y')
{
add(ph);
return;
}
else if(ch=='N'||ch=='n')
{
c=getchar();
return ;
}
}
else
{
printf("请输入要删除的联系人姓名:");
scanf("%s",dele_name);
t=sele(ph,dele_name);
p=ph;
printf("\n是否要删除该联系人信息(Y/N)\n");
ch=getch();
if(ch=='Y'||ch=='y')
{
while(p->next!=NULL)
{
if(strcmp(p->next->name,t->name)==0)
{
p->next=p->next->next;
free(t);
printf("信息删除成功!");
c=getch();
return ;
}
p=p->next;
}
}
else if(ch=='N'||ch=='n')
{
return;
}
}
}
void modify(phone_book * ph)
{
phone_book *t;
char modify_name[10],modify_number[15],modify_team[10];
char ch,ch1,ch2,c;
system("cls");
printf("=============联系人修改=============\n");
if(ph->next==NULL)
{
printf("联系人为空,是否要输入联系人信息(Y/N):");
ch=getchar();
if(ch=='Y'||ch=='y')
add(ph);
else if(ch=='N'||ch=='n')
{
c=getchar();
return ;
}
}
else
{
printf("请输入你要修改人的姓名:");
scanf("%s",modify_name);
t=sele(ph,modify_name);
printf("\n确定要修改吗(Y/N)\n");
ch1=getch();
if(ch1=='Y'||ch1=='y')
{
printf("联系人姓名:");
scanf("%s",modify_name);
printf("号码:");
scanf("%s",modify_number);
strcpy(t->name,modify_name);
strcpy(t->number,modify_number);
printf("是否要修改分组(Y/N)\n");
ch2=getch();
if(ch2=='Y'||ch2=='y')
{
printf("请输入分组名:");
scanf("%s",modify_team);
strcpy(t->team_name,modify_team);
printf("信息修改成功!");
c=getch();
return;
}
else if(ch2=='N'||ch2=='n')
{
printf("信息修改成功");
c=getch();
return;
}
}
else if(ch1=='N'||ch1=='n')
return;
}
}
void print(phone_book *ph)
{
phone_book *p;
char ch;
system("cls");
printf("===============================\n");
p=ph->next;
if(p==NULL)
{
printf("电话薄没有信息\n");
ch=getch();
return;
}
else
{
printf("姓名 号码 分组\n");
while(p!=NULL)
{
printf("%s %s %s\n",p->name,p->number,p->team_name);
p=p->next;
}
ch=getch();
return;
}
}
void save(phone_book *ph)
{
FILE *fp;
phone_book *p;
char ch;
p=ph->next;
if((fp=fopen("phone_book_disgn","wb"))==NULL)
{
printf("cannot open this file\n");
exit(0);
}
while(p!=NULL)
{
fwrite(p,max,1,fp);
p=p->next;
}
fclose(fp);
printf("信息保存成功");
ch=getch();
return;
}
void insert(phone_book * ph)
{
int i,k=0;
char ch;
phone_book *p,*t;
char insert_name[10],insert_number[15],insert_team[10];
system("cls");
p=ph->next;
printf("===================联系人插入================\n");
if(p==NULL)
{
printf("电话薄为空");
ch=getch();
return;
}
else
{
printf("你想插入的位置:");
scanf("%d",&i);
while(k!=i-1&&p!=NULL)
{
p=p->next;
k++;
}
t=(phone_book *)malloc(max);
printf("联系人姓名:");
scanf("%s",insert_name);
printf("联系人号码:");
scanf("%s",insert_number);
printf("联系人分组:");
scanf("%s",insert_team);
strcpy(t->name,insert_name);
strcpy(t->number,insert_number);
strcpy(t->team_name,insert_team);
t->next=p->next;
p->next=t;
printf("信息插入成功\n");
ch=getch();
return;
}
}
int main()
{
phone_book *p;
phone_book * t;
int chose;
char chose_name[10];
p=(phone_book*)malloc(max);
p->next=NULL;
do
{
system("cls");
printf("=============================================\n");
printf("| 1.Add information of linkman |\n");
printf("| 2.Select information of linkman |\n");
printf("| 3.Delete information of linkman |\n");
printf("| 4.Modify information of linkman |\n");
printf("| 5.Print information of linkman |\n");
printf("| 6.Save information |\n");
printf("| 7.Insert information of linkman |\n");
printf("| 0.Quit the System |\n");
printf("=============================================\n");
printf("pelease give your choice:");
scanf("%d",&chose);
while(chose>7||chose<0)
{
printf("超出选择范围,请重新输入:");
scanf("%d",&chose);
}
switch(chose)
{
case 1: add(p);break;
case 2: system("cls");
printf("please input your name:");
scanf("%s",chose_name);
t=sele(p,chose_name);
break;
case 3: dele(p);break;
case 4: modify(p);break;
case 5: print(p);break;
case 6: save(p);break;
case 7: insert(p);break;
}
}while(chose!=0);
printf("\n");
printf("Thank you for using the system!\n");
return 0;
}
本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。