|
|
#include<stdio.h>
|
|
|
#include<string.h>
|
|
|
|
|
|
typedef struct //结构体
|
|
|
{
|
|
|
char xh[12];
|
|
|
char name[20];
|
|
|
char xb[8];
|
|
|
char year[8];
|
|
|
char bz[800];
|
|
|
}Student;
|
|
|
|
|
|
void stdudent_ll()
|
|
|
{
|
|
|
Student Stu;
|
|
|
FILE *fp;
|
|
|
int flag=1;
|
|
|
fp=fopen("back.txt","a+");
|
|
|
if(fp==NULL)
|
|
|
{
|
|
|
printf("open file error!");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
while(flag==1)
|
|
|
{
|
|
|
printf("input student_学号:");
|
|
|
scanf("%s",Stu.xh);
|
|
|
printf("input student_姓名:");
|
|
|
scanf("%s",Stu.name);
|
|
|
printf("input student_性别:");
|
|
|
scanf("%s",Stu.xb);
|
|
|
printf("input student_年龄:");
|
|
|
scanf("%s",Stu.year);
|
|
|
printf("input student_备注:");
|
|
|
scanf("%s",Stu.bz);
|
|
|
printf("是否录入(是 输入 1 否 输入 2)\n");
|
|
|
int f;
|
|
|
scanf("%d",&f);
|
|
|
if(f==1)
|
|
|
{
|
|
|
fprintf(fp,"\n");
|
|
|
fprintf(fp,"");
|
|
|
fprintf(fp,"%s %s %s %s %s ",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
}
|
|
|
printf(" press '1'to continue,'0' exit:");
|
|
|
scanf("%d",&flag);
|
|
|
}
|
|
|
}
|
|
|
fclose(fp);
|
|
|
|
|
|
printf("已录入成功\n");
|
|
|
}
|
|
|
|
|
|
void stdudent_xs()
|
|
|
{
|
|
|
FILE *fp;
|
|
|
char ch;
|
|
|
int n=1;
|
|
|
fp=fopen("student.txt","a+");
|
|
|
if(fp==NULL)
|
|
|
{
|
|
|
printf("无法打开文件\n");
|
|
|
n=0;
|
|
|
}
|
|
|
ch=fgetc(fp);
|
|
|
while(ch!=EOF)
|
|
|
{
|
|
|
putchar(ch);
|
|
|
ch=fgetc(fp);
|
|
|
}
|
|
|
printf("\n");
|
|
|
}
|
|
|
|
|
|
void stdudent_bc()
|
|
|
{
|
|
|
FILE *fp=fopen("back.txt","r");
|
|
|
|
|
|
char jiey[20]={};Student Stu;
|
|
|
if(fp==NULL)
|
|
|
{
|
|
|
printf("");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
FILE *fm=fopen("student.txt","w");
|
|
|
while(!feof(fp))
|
|
|
{
|
|
|
|
|
|
fscanf(fp,"%s %s %s %s %s",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
if(strcmp(jiey,Stu.xh)!=0)
|
|
|
{
|
|
|
fprintf(fm,"%s %s %s %s %s",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
fprintf(fm,"\n");
|
|
|
}
|
|
|
strcpy(jiey,Stu.xh);
|
|
|
}
|
|
|
fclose(fm);
|
|
|
}
|
|
|
fclose(fp);printf("已保存\n");
|
|
|
}
|
|
|
|
|
|
void stdudent_sc()
|
|
|
{
|
|
|
FILE *fp;
|
|
|
int dot=1;
|
|
|
char target[20],jiey[12]={};
|
|
|
Student Stu;
|
|
|
fp=fopen("student.txt","a+");
|
|
|
while(dot==1)
|
|
|
{
|
|
|
printf("输入学号,退出按确定");
|
|
|
scanf("%s",target);
|
|
|
FILE *out;out=fopen("back.txt","w"); /*out是充当临时文件作用*/
|
|
|
while(!feof(fp))
|
|
|
{
|
|
|
fscanf(fp,"%s %s %s %s %s",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
if(strcmp(target,Stu.xh)!=0&&strcmp(Stu.xh,jiey)!=0)
|
|
|
{
|
|
|
fprintf(out,"%s %s %s %s %s",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
fprintf(out,"\n");
|
|
|
}
|
|
|
strcpy(jiey,Stu.xh);
|
|
|
}
|
|
|
rewind(fp);rewind(out);fclose(out);
|
|
|
dot=0;
|
|
|
}
|
|
|
printf("已删除,请保存\n"); fclose(fp);
|
|
|
}
|
|
|
|
|
|
|
|
|
void stdudent_xg()
|
|
|
{
|
|
|
char mm[16],ymm[16];
|
|
|
int flag=1;
|
|
|
FILE *fm;
|
|
|
fm=fopen("mima.txt","r+");
|
|
|
fscanf(fm,"%s",ymm);
|
|
|
fclose(fm);
|
|
|
printf("请输入密码:");
|
|
|
while(flag==1)
|
|
|
{
|
|
|
scanf("%s",mm);
|
|
|
if(strcmp(ymm,mm)==0)
|
|
|
{
|
|
|
FILE *fp;
|
|
|
int dot=1;int m=0;
|
|
|
char target[20],jiey[12]={};
|
|
|
Student Stu;
|
|
|
fp=fopen("student.txt","a+");
|
|
|
while(dot==1)
|
|
|
{
|
|
|
printf("输入学号,退出按0\n");
|
|
|
char s[5]={0};
|
|
|
scanf("%s",target);
|
|
|
if(strcmp(target,s)!=0)
|
|
|
{
|
|
|
|
|
|
FILE *out;out=fopen("back.txt","w"); /*out是充当临时文件作用*/
|
|
|
|
|
|
while(!feof(fp))
|
|
|
{
|
|
|
fscanf(fp,"%s %s %s %s %s",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
if(strcmp(target,Stu.xh)!=0&&strcmp(Stu.xh,jiey)!=0)
|
|
|
{
|
|
|
fprintf(out,"%s %s %s %s %s",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
fprintf(out,"\n");
|
|
|
}
|
|
|
else if(strcmp(target,Stu.xh)==0&&strcmp(Stu.xh,jiey)!=0)
|
|
|
{
|
|
|
printf("%s %s %s %s %s\n",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
printf("是否修改(是 输入 1 and 否 输入 2)\n");
|
|
|
int b;scanf("%d",&b);
|
|
|
if(b==1);
|
|
|
{
|
|
|
printf("请输入学号");scanf("%s",Stu.xh);
|
|
|
printf("请输入姓名");scanf("%s",Stu.name);
|
|
|
printf("请输入性别");scanf("%s",Stu.xb);
|
|
|
printf("请输入年龄");scanf("%s",Stu.year);
|
|
|
printf("请输入备注");scanf("%s",Stu.bz);
|
|
|
fprintf(out,"%s %s %s %s %s",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
fprintf(out,"\n"); m=1;
|
|
|
}
|
|
|
if(b==2)
|
|
|
{
|
|
|
fprintf(out,"%s %s %s %s %s",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
fprintf(out,"\n");
|
|
|
}
|
|
|
}
|
|
|
strcpy(jiey,Stu.xh);
|
|
|
}
|
|
|
rewind(fp);rewind(out); fclose(out);
|
|
|
if(m==0) printf("no find\n");
|
|
|
}
|
|
|
dot=0; fclose(fp);flag=0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("密码输入错误");
|
|
|
printf("再次输入按 1 退出按 2\n");
|
|
|
int a;
|
|
|
scanf("%d",&a);
|
|
|
if(a==2)
|
|
|
{
|
|
|
flag=0;
|
|
|
}
|
|
|
if(a==1)
|
|
|
{
|
|
|
printf("请再次输入");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
void stdudent_cx()
|
|
|
{
|
|
|
FILE *fp;
|
|
|
int n,flag=0;
|
|
|
char target[30],s[3]={0},jiey[20]={123};
|
|
|
Student Stu;
|
|
|
int dot=0;
|
|
|
fp=fopen("student.txt","a+");
|
|
|
if(fp==NULL)
|
|
|
{
|
|
|
printf("无法打开文件\n");
|
|
|
}
|
|
|
while(dot==0)
|
|
|
{
|
|
|
printf(" ***请输入查询方式***");
|
|
|
printf(" ***0.退出***\n");
|
|
|
printf(" ***1.按学号***\n");
|
|
|
printf(" ***2.按姓名***\n");
|
|
|
printf(" ***3.按性别***\n");
|
|
|
printf(" ***4.按年龄***\n");
|
|
|
scanf("%d",&n);
|
|
|
while(n!=0)
|
|
|
{
|
|
|
if(n==1)
|
|
|
{
|
|
|
printf("退出按0\n");printf("请输入学号\n");
|
|
|
gets(target);
|
|
|
}
|
|
|
else if(n==2)
|
|
|
{
|
|
|
printf("退出按0\n");printf("请输入姓名\n");
|
|
|
gets(target);
|
|
|
}
|
|
|
else if(n==3)
|
|
|
{
|
|
|
printf("退出按0\n");printf("请输入性别\n");
|
|
|
gets(target);
|
|
|
}
|
|
|
else if(n==4)
|
|
|
{
|
|
|
printf("退出按0\n");printf("请输入年龄\n");
|
|
|
gets(target);
|
|
|
}
|
|
|
gets(target);
|
|
|
if(strcmp(target,s)!=0)
|
|
|
{
|
|
|
while(!feof(fp))
|
|
|
{
|
|
|
fscanf(fp,"%s %s %s %s %s",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
if((strcmp(target,Stu.xh)==0||strcmp(target,Stu.name)==0||strcmp(target,Stu.year)==0||strcmp(target,Stu.xb)==0)&&strcmp(Stu.xh,jiey)!=0)
|
|
|
{
|
|
|
printf("%s %s %s %s %s\n",Stu.xh,Stu.name,Stu.xb,Stu.year,Stu.bz);
|
|
|
flag=1;
|
|
|
}
|
|
|
strcpy(jiey,Stu.xh);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dot=1;flag=1;n=0;
|
|
|
}
|
|
|
if(flag==0)
|
|
|
{
|
|
|
printf("no find\n");
|
|
|
}
|
|
|
n=0;
|
|
|
}
|
|
|
if(n==0)
|
|
|
{
|
|
|
dot=1;
|
|
|
}
|
|
|
}
|
|
|
printf("\n");
|
|
|
}
|
|
|
|
|
|
int main()
|
|
|
{
|
|
|
printf("\t\t\t班级档案管理系统\n");
|
|
|
char mm[16],ymm[16];
|
|
|
int flag=1,q=0;
|
|
|
FILE *fm;
|
|
|
fm=fopen("mima.txt","r+");
|
|
|
printf("请输入密码:");
|
|
|
fscanf(fm,"%s",ymm);
|
|
|
fclose(fm);
|
|
|
while(flag==1)
|
|
|
{
|
|
|
int zhong=1;
|
|
|
scanf("%s",mm);
|
|
|
while(zhong==1)
|
|
|
{
|
|
|
if(strcmp(mm,ymm)==0)
|
|
|
{
|
|
|
printf(" *********请选择系统功能项*********\n");
|
|
|
printf(" *******1*学生基本信息录入*********\n");
|
|
|
printf(" *******2*学生基本信息显示*********\n");
|
|
|
printf(" *******3*学生基本信息保存*********\n");
|
|
|
printf(" *******4*学生基本信息删除*********\n");
|
|
|
printf(" *******5*学生基本信息修改*********\n");
|
|
|
printf(" *******6*学生基本信息查询*********\n");
|
|
|
printf(" *******7*****退出系统*************\n");
|
|
|
printf("请输入:");
|
|
|
int n;
|
|
|
scanf("%d",&n);
|
|
|
switch(n)
|
|
|
{
|
|
|
case 1:stdudent_ll();break;
|
|
|
case 2:stdudent_xs();break;
|
|
|
case 3:stdudent_bc();q=1;break;
|
|
|
case 4:stdudent_sc();break;
|
|
|
case 5:stdudent_xg();break;
|
|
|
case 6:stdudent_cx();break;
|
|
|
case 7:zhong=0;flag=0;if(q==0) {remove("back.txt");} break;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
int m;zhong=0;
|
|
|
printf("密码错误\n");
|
|
|
printf("继续按 1 退出按 2\n");
|
|
|
scanf("%d",&m);
|
|
|
if(m!=1)
|
|
|
{
|
|
|
flag=0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("请再次输入密码:\n");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|