#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include <windows.h>
typedef struct staff
{
int sno;
char name[20];
char xingbie[5];
char cs[50];
char xueli[20];
char zhiwu[20];
int gongzi;
char zhuzhi[100];
long long int number;
struct staff *next;
}STA;
STA *head;
FILE *fp;
STA *found() //创建信息
{
int n;
STA *p=NULL,*pre=NULL; //定义指针变量
pre=head=(STA *)malloc(sizeof(STA)); //申请内存
head->next=NULL;
while(1)
{
p=(STA*)malloc(sizeof (STA));
printf("输入职工的编号、姓名、性别、出生年月、学历、职务、工资、住址、电话:\n");
printf("编号:");
scanf("%d",&p->sno);
printf("姓名:");
scanf("%s",&p->name);
printf("性别:");
scanf("%s",&p->xingbie);
printf("出生年月:");
scanf("%s",&p->cs);
printf("学历:");
scanf("%s",&p->xueli);
printf("职务:");
scanf("%s",&p->zhiwu);
printf("工资:");
scanf("%d",&p->gongzi);
printf("住址:");
scanf("%s",&p->zhuzhi);
printf("电话:");
scanf("%lld",&p->number);
printf("\n");
pre->next=p;
pre=p;
printf("============================================\n");
printf("是否继续创建下一个职工信息 否:输1 继续: 输2\n");
scanf("%d",&n);
if(n==1)
{
pre->next=NULL;
p=NULL;
//return head;
break;
}
printf("\n");
if(n>2)
{
printf("输入错误!\n");
system("pause");
}
}
pre->next=NULL;
// free(p);
p=NULL;
return head;
}
void baocun(STA *head)
{
STA *p,*p1;
p=head->next;
FILE *fp;
fp=fopen("E:/zhigong.txt","w");
if(fp==NULL)
{
printf("文件保存失败!");
return ;
}
if(p==NULL)
{
printf("链表为空!");
return ;
}
p=head->next;
while(p!=NULL)
{
fprintf(fp,"%d %s %s %s %s %s %d %s %lld\n",p->sno,p->name,p->xingbie,p->cs,p->xueli,p->zhiwu,p->gongzi,p->zhuzhi,p->number);
p=p->next;
}
fclose(fp);
printf("职工信息保存成功!\n");
return ;
}
void chaxun(STA *head)//查询信息
{
STA *p=NULL;
int n,i=0;
int sno1;
char name1[100];
system("cls");
printf("\t\t 请选择方式查找职工信息: \n");
printf("\t\t 1.通过编号查找 2.通过姓名查找\n"); //查询方式
p=head->next;
if(p==NULL)
{
printf("没有职工信息,请先保存职工信息!\n");
}
printf("===========================\n");
printf("请输入您的选择: 1 或 2 \n");
scanf("%d",&n);
switch(n)
{
case 1:
printf("请输入要查找的职工的编号:\n");
scanf("%d",&sno1);
while(p!=NULL)
{
if(sno1==p->sno)
{
printf("成功找到此职工信息!\n");
printf("职工的编号、姓名、性别、出生年月、学历、职务、工资、住址、电话:\n");
printf("编号:%d\n",p->sno);
printf("姓名:%s\n",p->name);
printf("性别:%s\n",p->xingbie);
printf("出生年月:%s\n",p->cs);
printf("学历:%s\n",p->xueli);
printf("职务:%s\n",p->zhiwu);
printf("工资:%d\n",p->gongzi);
printf("住址:%s\n",p->zhuzhi);
printf("电话:%lld\n",p->number);
i=1;
break;
}
p=p->next;
}
if(i==0)
printf("未查找到此职工信息!\n");
break;
case 2:
printf("请输入要查找的职工的姓名:\n");
scanf("%s",&name1);
while(p!=NULL)
{
if(strcmp(p->name,name1)==0)
{
printf("成功找到此职工信息!\n");
printf("职工的编号、姓名、性别、出生年月、学历、职务、工资、住址、电话:\n");
printf("编号:%d\n",p->sno);
printf("姓名:%s\n",p->name);
printf("性别:%s\n",p->xingbie);
printf("出生年月:%s\n",p->cs);
printf("学历:%s\n",p->xueli);
printf("职务:%s\n",p->zhiwu);
printf("工资:%d\n",p->gongzi);
printf("住址:%s\n",p->zhuzhi);
printf("电话:%lld\n",p->number);
i=1;
break;
}
p=p->next;
}
if(i==0)
printf("未查找到此职工信息!\n");
break;
default:printf("查找有错误!\n");
}
}
void xiugai(STA *head)
{
STA *p=NULL,*p1=head->next;
int n,i=0;
int sno2;
char name2[100];
p=head->next;
if(p==NULL)
{
printf("没有职工信息,请先保存职工信息!\n");
}
system("cls");
printf("\t\t 请选择方式查找需要修改的目标职工: \n");
printf("\t\t 1.通过编号修改 2.通过姓名修改\n");
printf("===========================\n");
printf("请输入您的选择: 1 或 2 \n");
scanf("%d",&n);
switch(n)
{
case 1:
printf("请输入被修改的职工编号:\n");
scanf("%d",&sno2);
while(p!=NULL)
{
if(p->sno==sno2)
{
printf("输入职工的编号、姓名、性别、出生年月、学历、职务、工资、住址、电话:\n");
printf("编号:");
scanf("%d",&p->sno);
printf("姓名:");
scanf("%s",&p->name);
printf("性别:");
scanf("%s",&p->xingbie);
printf("出生年月:");
scanf("%s",&p->cs);
printf("学历:");
scanf("%s",&p->xueli);
printf("职务:");
scanf("%s",&p->zhiwu);
printf("工资:");
scanf("%d",&p->gongzi);
printf("住址:");
scanf("%s",&p->zhuzhi);
printf("电话:");
scanf("%lld",&p->number);
printf("对编号的修改成功!\n");
i=1;
break;
}
p=p->next;
}
if(i==0)
printf("未找到目标职工!\n");
break;
case 2:
printf("请输入被修改的姓名:\n");
scanf("%s",&name2);
while(p!=NULL)
{
if(strcmp(p->name,name2)==0)
{
printf("输入职工的编号、姓名、性别、出生年月、学历、职务、工资、住址、电话:\n");
printf("编号:");
scanf("%d",&p->sno);
printf("姓名:");
scanf("%s",&p->name);
printf("性别:");
scanf("%s",&p->xingbie);
printf("出生年月:");
scanf("%s",&p->cs);
printf("学历:");
scanf("%s",&p->xueli);
printf("职务:");
scanf("%s",&p->zhiwu);
printf("工资:");
scanf("%d",&p->gongzi);
printf("住址:");
scanf("%s",&p->zhuzhi);
printf("电话:");
scanf("%lld",&p->number);
printf("对编号的修改成功!\n");
i=1;
break;
}
p=p->next;
}
if(i==0)
printf("未找到目标职工!\n");
break;
default:printf("修改内容有错误!\n");
}
}
void tianjia(STA *head) //添加信息
{
int n;
FILE *fp;
fp=fopen("E:/zhigong.txt","a");
STA *p=NULL,*p1=NULL;
p=head->next;
while(p->next!=NULL)
{
p=p->next;
}
while(1)
{
p1=(STA*)malloc(sizeof(STA));
printf("请输入你所想添加的信息:\n");
printf("编号:");
scanf("%d",&p1->sno);
printf("姓名:");
scanf("%s",&p1->name);
printf("性别:");
scanf("%s",&p1->xingbie);
printf("出生年月:");
scanf("%s",&p1->cs);
printf("学历:");
scanf("%s",&p1->xueli);
printf("职务:");
scanf("%s",&p1->zhiwu);
printf("工资:");
scanf("%d",&p1->gongzi);
printf
- 1
- 2
- 3
- 4
- 5
- 6
前往页