大家看一下这个学生学籍管理系统的错误?
#include <stdio.h>#include <string.h>
#include <conio.h>
#include <malloc.h>
#include <stdlib.h>
#define N 100
struct student
{char XUEHAO[20];
char XINGMING[10];
char XINGBIE[4];
char SHENGRI[10];
char JIGUAN[10];
char ZHUANYE[10];
char BANJI[6];
char XUEYUAN[20];
}student;
void CAIDAN();
void ZHUCE();
void XIUGAI();
void SHANCHU();
void del_XUEHAO(FILE *fp);
void del_XINGMING(FILE *fp);
void CHAZHAO();
void sch_XUEHAO(FILE *fp);
void sch_XINGMING(FILE *fp);
void TONGJI();
void XIANSHI();
void TIANJIA();
void save( struct student student[]);
main()
{ char choose,yes_no;
do
{ CAIDAN();
printf("\n 请输入序号: (1~8) ");
choose=getch();
system("cls");
switch(choose)
{
case'1': printf(" %c",choose);ZHUCE();break;
case'2': printf(" %c",choose);XIUGAI();break;
case'3': printf(" %c",choose);SHANCHU();break;
case'4': printf(" %c",choose);TIANJIA();break;
case'5': printf(" %c",choose);CHAZHAO();break;
case'6': printf(" %c",choose);TONGJI();break;
case'7': printf(" %c",choose);XIANSHI();break;
case'8': break;
default:printf("\n %c 序号不对!\n",choose);
}
if(choose=='8')break;
printf("\n 要继续选择吗 ? (Y/N) \n");
do
{ yes_no=getch(); printf(" %c",yes_no);}
while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n');
}while(yes_no=='Y'||yes_no=='y');
}
void CAIDAN()
{
system("cls");
printf(" **************************************** \n ");
printf(" * ——请选择相应的功能—— * \n ");
printf(" * 1-----注册 * \n ");
printf(" * 2-----修改学生信息 * \n ");
printf(" * 3-----删除学生信息 * \n ");
printf(" * 4-----添加学生信息 * \n ");
printf(" * 5-----查找学生信息 * \n ");
printf(" * 6-----统计学生信息 * \n ");
printf(" * 7-----显示学生信息 * \n ");
printf(" * 8-----退出系统 * \n ");
printf(" **************************************** \n ");
}
/*定义学生信息注册的函数*/
void ZHUCE()
{ int i=1;
struct student temp;
FILE *fp;
fp=fopen("E://123.txt","w");
if(fp==NULL){ printf("\n 打开文件失败! \n");return; }
printf("\n 请输入第1个学生信息:\n");
printf(" 学号(用#结束输入): ");
do
{ gets(temp.XUEHAO);}
while(strcmp(temp.XUEHAO," ")==0);
printf(" 姓名(用#结束输入): ");gets(temp.XINGMING);
printf(" 性别(用#结束输入): ");gets(temp.XINGBIE);
printf(" 生日(用#结束输入): ");gets(temp.SHENGRI);
printf(" 籍贯(用#结束输入): ");gets(temp.JIGUAN);
printf(" 专业(用#结束输入): ");gets(temp.ZHUANYE);
printf(" 班级(用#结束输入): ");gets(temp.BANJI);
printf(" 学院(用#结束输入): ");gets(temp.XUEYUAN);
while(temp.XUEHAO[0]!='#'&&temp.XINGMING[0]!='#'&&temp.XINGBIE[0]!='#'&&temp.SHENGRI[0]!='#'&&temp.JIGUAN[0]!='#'&&temp.ZHUANYE[0]!='#'&&temp.BANJI[0]!='#'&&temp.XUEYUAN[0]!='#')
{ fprintf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",temp.XUEHAO,temp.XINGMING,temp.XINGBIE,temp.SHENGRI,temp.JIGUAN,temp.ZHUANYE,temp.BANJI,temp.XUEYUAN,temp);
i++;
printf("\n 请输入第 %d 个学生信息:\n ",i);
printf(" 学号(用#结束输入): ");
do
{ gets(temp.XUEHAO);}
while(strcmp(temp.XUEHAO," ")==0);
printf(" 姓名(用#结束输入): ");gets(temp.XINGMING);
printf(" 性别(用#结束输入): ");gets(temp.XINGBIE);
printf(" 生日(用#结束输入): ");gets(temp.SHENGRI);
printf(" 籍贯(用#结束输入): ");gets(temp.JIGUAN);
printf(" 专业(用#结束输入): ");gets(temp.ZHUANYE);
printf(" 班级(用#结束输入): ");gets(temp.BANJI);
printf(" 学院(用#结束输入): ");gets(temp.XUEYUAN);
}
student=temp;
save(&temp);
fclose(fp);
}
/*定义保存函数*/
void save( struct student student[])
{
FILE *fp=NULL;
fp=fopen("E://123.txt","ab+");
fwrite(student,sizeof(struct student),1,fp);
fclose(fp);
}
/*定义查找学生信息的函数*/
void CHAZHAO()
{ char c;
FILE *fp;
fp=fopen("G://123.txt","r");
if(fp==NULL)
{ printf("\n 打开文件失败! \n");return; }
printf("\n 按学号查找( 1 ),还是按姓名查找( 2 )? ");
c=getch();
putch(c);
if(c=='1') sch_XUEHAO(fp);
else if(c=='2') sch_XINGMING(fp);
else printf("\n 非法字符!\n");
fclose(fp);
}
/*定义按学号查找学生信息的函数*/
void sch_XUEHAO(FILE *fp)
{ int flag=0,n=0;
char tempXUEHAO[20];
struct student temp;
printf("\n 请输入要查找学生信息的学号: ");
gets(tempXUEHAO);
while(feof(fp)==0)
{ fscanf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",&temp.XUEHAO,&temp.XINGMING,&temp.XINGBIE,&temp.SHENGRI,&temp.JIGUAN,&temp.ZHUANYE,&temp.BANJI,&temp.XUEYUAN);
if(strcmp(tempXUEHAO,temp.XUEHAO)==0)
{ if(flag==0)
printf(" 学号 姓名 性别 生日 籍贯 专业 班级 学院\n");
printf("%5s%10s%10s%10s%10s%10s%10s%10s\n",temp.XUEHAO,temp.XINGMING,temp.XINGBIE,temp.SHENGRI,temp.JIGUAN,temp.ZHUANYE,temp.BANJI,temp.XUEYUAN);
flag=1;
}
n++;
}
if(n==0) printf("\n 文件中无此信息!\n");
else if(flag==0) printf("\n 文件中无此人!\n");
}
/*定义按姓名查找学生信息的函数*/
void sch_XINGMING(FILE *fp)
{ int flag=0,n=0;
char tempXINGMING[10];
struct student temp;
printf("\n 请输入要查找学生信息的姓名: ");
gets(tempXINGMING);
while(feof(fp)==0)
{ fscanf(fp, "%5s%10s%10s%10s%10s%10s%10s%10s\n",&temp.XUEHAO,&temp.XINGMING,&temp.XINGBIE,&temp.SHENGRI,&temp.JIGUAN,&temp.ZHUANYE,&temp.BANJI,&temp.XUEYUAN);
if(strcmp(tempXINGMING,temp.XINGMING)==0)
{ if(flag==0) printf(" 学号 姓名 性别 生日 籍贯 专业 班级 学院\n");
printf("%5s%10s%10s%10s%10s%10s%10s%10s\n",temp.XUEHAO,temp.XINGMING,temp.XINGBIE,temp.SHENGRI,temp.JIGUAN,temp.ZHUANYE,temp.BANJI,temp.XUEYUAN);
flag=1;
}
n++;
}
if(n==0) printf("\n 文件中无此信息!\n");
else if(flag==0) printf("\n 文件中无此人!\n");
}
/*定义删除学生信息的函数*/
void SHANCHU()
{ char c;
FILE *fp;
fp=fopen("E://123.txt","r");
if(fp==NULL)
{ printf("\n 文件打开失败!\n ");return; }
printf("\n 按学号删除( 1 ),还是按姓名删除( 2 )? ");
c=getch();
putch(c);
if(c=='1') del_XUEHAO(fp);
else if(c=='2') del_XINGMING(fp);
else printf("\n 非法字符!\n");
}
/*定义按学号删除学生信息的函数*/
void del_XUEHAO(FILE *fp)
{ char tempXUEHAO[20];
int n=0,i=0,k;
struct student stu[N];
while(feof(fp)==0)
{ fscanf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",stu[i].XUEHAO,stu[i]. XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].ZHUANYE,stu[i].BANJI,stu[i].XUEYUAN);i++;n++;}
fclose(fp);
printf("\n 请输入要删除的学生信息的学号:");
scanf("%s",tempXUEHAO);
printf(" 删除成功! ");
for(i=0;i<n;i++)
if(strcmp(tempXUEHAO,stu[i].XUEHAO)==0)break;
if(i<n)
for(k=i;k<n;k++)
stu[k]=stu[k+1];
else printf("\n 无此人!\n");
fp=fopen("E://123.txt","w");
if(fp==NULL)
{ printf("\n 文件打开失败!\n");return; }
for(i=0;i<n-1;i++)
fprintf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",stu[i].XUEHAO,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].ZHUANYE,stu[i].BANJI,stu[i].XUEYUAN);
}
/*定义按姓名删除学生信息的函数*/
void del_XINGMING(FILE *fp)
{ char tempXINGMING[10];
int n=0,i=0,k;
struct student stu[N];
while(feof(fp)==0)
{ fscanf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",stu[i].XUEHAO,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].ZHUANYE,stu[i].BANJI,stu[i].XUEYUAN);i++;n++;}
fclose(fp);
printf("\n 请输入要删除的学生信息的姓名:");
scanf("%s",tempXINGMING);
printf(" 删除成功! ");
for(i=0;i<n;i++)
if(strcmp(tempXINGMING,stu[i].XINGMING)==0)break;
if(i<n)
for(k=i;k<n;k++)
stu[k]=stu[k+1];
else printf("\n 无此人!\n");
fp=fopen("E://123.txt","w");
if(fp==NULL)
{ printf("\n 文件打开失败!\n");return;}
for(i=0;i<n-1;i++)
fprintf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",stu[i].XUEHAO,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].ZHUANYE,stu[i].BANJI,stu[i].XUEYUAN);
}
/*定义添加学生信息的函数*/
void TIANJIA()
{ char c;
int n=0,i=0;
struct student temp,stu[N];
FILE *fp;
fp=fopen("G://123.txt","r");
if(fp==NULL)
{ printf("\n 打开文件失败!\n"); return; }
while(feof(fp)==0)
{ fscanf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",stu[i].XUEHAO,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].ZHUANYE,stu[i].BANJI,stu[i].XUEYUAN);i++;n++;}
fclose(fp);
for(i=0;i<n;i++)
printf("\n %s %s %s %s %s %s %s %s\n",stu[i].XUEHAO,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].ZHUANYE,stu[i].BANJI,stu[i].XUEYUAN);
do
{ printf("\n 请输入新学生信息的学号:");
do
{ scanf("%s",temp.XUEHAO); }
while(strcmp(temp.XUEHAO," ")==0);
printf(" 请输入新学生信息的姓名:");scanf("%s",temp.XINGMING);
printf(" 请输入新学生信息的性别:");scanf("%s",temp.XINGBIE);
printf(" 请输入新学生信息的生日:");scanf("%s",temp.SHENGRI);
printf(" 请输入新学生信息的籍贯:");scanf("%s",temp.JIGUAN);
printf(" 请输入新学生信息的专业:");scanf("%s",temp.ZHUANYE);
printf(" 请输入新学生信息的班级:");scanf("%s",temp.BANJI);
printf(" 请输入新学生信息的学院:");scanf("%s",temp.XUEYUAN);
for(i=0;i<n;i++)
if(strcmp(temp.XUEHAO,stu[i].XUEHAO)==0)
{ printf("\n 学号重复,要重新输入吗(Y/N)?");
do
{ c=getch(); putch(c);}
while(c!='Y'&&c!='y'&&c!='N'&&c!='n');
putchar('\n');
break;
}
if(i==n) { stu[i]=temp; break; }
}while(c=='Y'||c=='y');
fp=fopen("E://123.txt","w");
if(fp==NULL)
{ printf("\n 文件打开失败!\n"); return; }
for(i=0;i<=n;i++)
fprintf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",stu[i].XUEHAO,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].ZHUANYE,stu[i].BANJI,stu[i].XUEYUAN);
fclose(fp);
}
/*定义修改学生信息的函数*/
void XIUGAI()
{ char c;
int n=0,i=0;
struct student *find,temp,stu[N],*p;
FILE *fp;
fp=fopen("E://123.txt","rb");
if(fp==NULL)
{ printf("\n 打开文件失败!\n"); return; }
while(feof(fp)==0)
{ fscanf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",stu[i].XUEHAO,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].ZHUANYE,stu[i].BANJI,stu[i].XUEYUAN);i++;n++;}
fclose(fp);
if(n==0)
{ printf("\n 文件中无此信息!\n");return;}
printf("\n 请输入要修改的学生信息的学号: ");scanf("%s",temp.XUEHAO);
for(p=stu;p<stu+n;p++)
if(strcmp(temp.XUEHAO,p->XUEHAO)==0)
{ find=p; break; }
if(p==stu+n)
{ printf("\n 无此信息!\n");return; }
do
{ printf("\n 请输入新学生信息的学号:");
do
{ scanf("%s",temp.XUEHAO); }
while(strcmp(temp.XUEHAO," ")==0);
printf(" 请输入新学生信息的姓名:");scanf("%s",temp.XINGMING);
printf(" 请输入新学生信息的性别:");scanf("%s",temp.XINGBIE);
printf(" 请输入新学生信息的生日:");scanf("%s",temp.SHENGRI);
printf(" 请输入新学生信息的籍贯:");scanf("%s",temp.JIGUAN);
printf(" 请输入新学生信息的专业:");scanf("%s",temp.ZHUANYE);
printf(" 请输入新学生信息的班级:");scanf("%s",temp.BANJI);
printf(" 请输入新学生信息的学院:");scanf("%s",temp.XUEYUAN);
for(p=stu;p<stu+n;p++)
if(strcmp(temp.XUEHAO,p->XUEHAO)==0&&p!=find)
{ printf("\n 学号重复,要重新输入吗(Y/N)?");
do
{ c=getch();putch(c);}
while(c!='Y'&&c!='y'&&c!='N'&&c!='n');putchar('\n');
break;
}
if(p==stu+n)
{ *find=temp; break; }
}while(c=='Y'||c=='y');
fp=fopen("123.dat","wb");
if(fp==NULL) { printf("\n 打开文件失败!\n "); return; }
for(p=stu;p<stu+n;p++)
fprintf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",p->XUEHAO,p->XINGMING,p->XINGBIE,p->SHENGRI,p->JIGUAN,p->ZHUANYE,p->XUEYUAN,p->BANJI);
printf (" 修改成功! ");
fclose(fp);
}
/*定义显示学生信息的函数*/
void XIANSHI()
{ int n=0,i=0;
struct student stu[N];
FILE *fp;
fp=fopen("E://123.txt","r");
if(fp==NULL)
{ printf("\n 打开文件失败!\n"); return; }
printf("\n\n 学号 姓名 性别 生日 籍贯 专业 班级 学院\n");
while(feof(fp)==0)
{ fscanf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",stu[i].XUEHAO,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].ZHUANYE,stu[i].BANJI,stu[i].XUEYUAN); ++i; ++n; }
fclose(fp);
if(n==0)
printf("\n 文件中无此信息!\n");
else { for(i=0;i<n;i++)
printf("%5s%10s%10s%10s%10s%10s%10s%10s\n",stu[i].XUEHAO,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].ZHUANYE,stu[i].BANJI,stu[i].XUEYUAN);
printf("\n\n 文件中共有 %d 个信息!\n",n);
}
}
/*定义在同一个学院的学生人数的函数*/
void TONGJI()
{ int i=0,n=0,k=0;
char tempXUEYUAN[10];
struct student stu[N];
FILE *fp;
fp=fopen("E://123.txt","r");
if(fp==NULL)
{ printf("\n 打开文件失败!\n"); return; }
while(feof(fp)==0)
{fscanf(fp,"%5s%10s%10s%10s%10s%10s%10s%10s\n",&stu[i].XUEHAO,&stu[i].XINGMING,&stu[i].XINGBIE,&stu[i].SHENGRI,&stu[i].JIGUAN,&stu[i].ZHUANYE,&stu[i].XUEYUAN,&stu[i].BANJI);i++;n++; }
fclose(fp);
printf("\n\n 请输入学院名称: ");
scanf("%s",tempXUEYUAN);
printf("\n\n 学号 姓名 姓别 生日 籍贯 专业 班级 学院\n");
for(i=0;i<n;i++)
if(strcmp(tempXUEYUAN,stu[i].XUEYUAN)==0)
{printf("\n%5s%10s%10s%10s%10s%10s%10s%10s\n",stu[i].XUEHAO,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].ZHUANYE,stu[i].BANJI,stu[i].XUEYUAN);
k++;
}
printf("\n\n 共有%d个学生在这个学院!\n",k);
}
输入4是出现? 输入7时出现?