You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
1.8 KiB
142 lines
1.8 KiB
#include <stdio.h>
|
|
#include <string.h>
|
|
struct worker
|
|
{
|
|
long int num;
|
|
char name[20];
|
|
int age;
|
|
char sex[4];
|
|
char b[30];
|
|
char p[15];
|
|
};
|
|
int n=0;
|
|
struct worker stu[100];
|
|
struct worker *p;
|
|
void lr();
|
|
void ll();
|
|
void cx();
|
|
void xg();
|
|
void sc();
|
|
void cd();
|
|
void save();
|
|
|
|
int main()
|
|
|
|
|
|
|
|
{int N;
|
|
|
|
printf("欢迎 \n ");
|
|
|
|
printf(" 1.进入主菜单\n");
|
|
|
|
printf(" 2.退出程序\n");
|
|
|
|
printf("请选择;");
|
|
|
|
scanf("%d",&N);//这里调用主菜单函数
|
|
|
|
if(N==1)
|
|
|
|
cd();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
//主菜单函数
|
|
|
|
void cd()
|
|
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
printf("1.录入\n");
|
|
|
|
printf("2.查询\n");
|
|
|
|
printf("3.搜索\n");
|
|
|
|
printf("4.修改\n");
|
|
|
|
printf("5.删除\n");
|
|
|
|
printf("请选择;");
|
|
|
|
scanf("%d",&x);
|
|
|
|
switch(x)
|
|
|
|
{
|
|
|
|
case 1: lr();break;
|
|
|
|
case 2: printf("查询");break;
|
|
|
|
case 3: printf("搜索");break;
|
|
|
|
case 4: printf("修改");break;
|
|
|
|
case 5: printf("删除");break;
|
|
|
|
default:printf("请输入正确数值");break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
void lr()/*录入函数*/
|
|
{
|
|
int y,s;
|
|
if(n==0)
|
|
p=stu;
|
|
do
|
|
{
|
|
printf("--------------------\n");
|
|
printf("请输入职工的职工号:");
|
|
scanf("%ld",&p->num);
|
|
printf("请输入职工的姓名:");
|
|
scanf("%s",p->name);
|
|
printf("请输入职工的年龄:");
|
|
scanf("%d",&p->age);
|
|
printf("请输入职工的性别:");
|
|
scanf("%s",p->sex);
|
|
printf("请输入职工的地址:");
|
|
scanf("%s",p->b);
|
|
printf("请输入职工的电话:");
|
|
scanf("%s",p->p);
|
|
n++;
|
|
p++;
|
|
printf("\n1.继续输入.\n0.输入完毕.\n");
|
|
printf("请选择:");
|
|
scanf("%d",&y);
|
|
}
|
|
while(y==1);
|
|
save();
|
|
//printf("提示:输入完毕!你一共输入%d个\n",n);
|
|
}
|
|
void save() /*建立保存文件函数*/
|
|
{
|
|
FILE *fp; /*定义文件型指针*/
|
|
int i;
|
|
if((fp=fopen("student.txt","wb"))==NULL) /*打开输出文件*/
|
|
{
|
|
printf("不能打开文件!\n");
|
|
return; /*终止程序*/
|
|
}
|
|
for(i=0;i<n;i++) /*向student文件中写入信息*/
|
|
if(fwrite(&stu[i],sizeof(struct worker),1,fp)!=1)
|
|
printf("文件写入错误\n");
|
|
fclose(fp); /*关闭文件*/
|
|
printf("\n\n\n\n\t\t\t学生信息保存成功!\n");
|
|
cd();
|
|
}
|