📄 taokeguanlixitong.txt
字号:
printf("\n查询下一个学生的个人信息(y/n)");
ch=getch();
if(ch=='y'||ch=='Y')
{ system("cls");
temp=(char *)malloc(20*sizeof(char)); //重新分配内存
printf("请输入要查询的学生姓名:");
continue; }
else
{ printf("\n查询结束,返回!");
getch();
system("cls");
return ; }
}
free(temp); //释放已经分配的内存空间
printf("\n输入有误,请按任意键返回子菜单!");
getch();
system("cls");
}
/****************************查询所有信息*******************************/
void allabout(struct allstudentinfo *p_student)
{ int i;
int count;
system("cls");
if((infofile=fopen(filename,"rb"))==NULL)
{ printf("不能打开文件,请确认文件是否存在或是否损坏!");
getch();
exit(1); }
rewind(infofile); //定位到文件头
for(count=0;fread(&p_student[count].student,sizeof(struct studentinfo),1,infofile)==1;count++)
{ continue; }
fclose(infofile); //读完后关闭文件
if(!count)
{ printf("不能读取数据,请确定文件是否存在或已经成功录入数据!");
getch();
system("cls");
return ; } //反回重新操作
printf("\n\t\t\t 学生个人信息查询表\n\n");
printf("\t 以下是本系统所查询到的所有学生个人信息,如果表中找不到数据\n");
printf(" 请确认是否已经成功录入本系统!\n");
printf("----------------------------------------");
printf("----------------------------------------\n");
for(i=0;i<count;i++)
{ printf("您正在查看第[%d]个学生的个人信息\n",i+1);
printf("\n姓 名: %s\n",p_student[i].student.name);
printf("\n性 别: %s\n",p_student[i].student.sex);
printf("\n旷课日期: %s\n",p_student[i].student.kdays);
printf("\n旷课科目: %s\n",p_student[i].student.addr);
printf("\n学生学号: %s\n",p_student[i].student.number);
printf("\n旷课数目: %s\n",p_student[i].student.dak);
printf("\n所在班级: %s\n",p_student[i].student.school);
printf("------------------------------------");
printf("------------------------------------\n");
printf("请按任意键继续查看信息........!");
getch();
system("cls");
}
printf("\n查询结束...");
printf("请按任意键返回!");
getch();
system("cls");
return ;
}
/****************************删除个人信息*******************************/
void delinfo(struct allstudentinfo *p_student)
{ int i;
int count;
char ch;
char *temp=NULL; //初始化临时数组
system("cls"); //清屏
if((infofile=fopen(filename,"rb"))==NULL)
{ printf("不能打开文件,请确认磁盘已满或文件是否存在");
getch();
exit(1); }
rewind(infofile); //指向文件头
for(count=0;fread(&p_student[count].student,sizeof(struct studentinfo),1,infofile)==1;count++)
{ continue; }
fclose(infofile); //关闭文件
if(!count)
{ printf("不能读取数据,请确认已经正确录入或数据是否存在");
getch();
return ; }
temp=(char *)malloc(20*sizeof(char)); //分配内存
printf("请输入你要删除的学生姓名:");
while(gets(temp)!=NULL&&temp[0]!='\0')
{ for(i=0;i<count;i++)
{ if(!strcmp(temp,p_student[i].student.name))
{ system("cls");
printf("\a\n\n\n\n\n\n\t\t 确定要删除%s的个人旷课信息吗?(y/n)",p_student[i].student.name);
ch=getch();
if(ch=='n'||ch=='N')
{ free(temp);
system("cls");
printf("\n\n\n\n\n\n\t\t 该操作已取消.请按任意键返回!");
getch();
system("cls");
return ; }
for(;i<count;i++)
{ p_student[i].student=p_student[i+1].student; }
count--; //删除一个学生信息
if((infofile=fopen(filename,"w+b"))==NULL) //重新打开文件更新
{ free(temp);
printf("不能打开文件,请确认磁盘已满或文件是否存在");
getch();
exit(1); }
for(i=0;i<count;i++)
{ //更新文件
if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)!=1)
break; }
free(temp); //释放内存
system("cls");
printf("\n\n\n\n\n\n\t\t 已成功删除该学生的个人旷课信息.....\n");
printf("\n\t\t确定要删除下一个学生个人信息(y/n)");
ch=getch();
if(ch=='n'||ch=='N')
{ fclose(infofile);
system("cls");
return ; }
else
{ system("cls");
temp=(char *)malloc(20*sizeof(char)); //重新分配内存以删除下一个信息
printf("请输入你想要删除的学生姓名:");
break; }
}
}
printf("找不到%s的个人信息.",temp);
printf("请重新输入(y/n)");
ch=getch();
if(ch=='y'||ch=='Y')
{ free(temp);
temp=(char *)malloc(sizeof(char)); //重新分配
system("cls");
printf("请输入你要删除的学生姓名:");
continue; }
else
{ free(temp);
system("cls");
return ; }
}
free(temp); //释放内存
printf("输入有误,请按任意键返回子菜单,重新选择");
getch();
system("cls"); }
/**********************修改学生姓名***************************/
void mofname(struct allstudentinfo *p_student)
{ char ch;
char *temp;
char *newtemp;
int count;
int i;
system("cls");
count=datfile(p_student); //处理文件
if(!count)
{ printf("读取数据失败,请确认已成功录入或文件数据是否损害!");
getch();
return ; }
newtemp=(char *)malloc(20*sizeof(char)); //分配内存
temp= (char *)malloc(20*sizeof(char)); //分配内存
printf("请输入您要修改的学生姓名:");
while(gets(temp)!=NULL&&temp[0]!='\0')
{ for(i=0;i<count;i++)
{ if(strcmp(temp,p_student[i].student.name))
{ continue; }
else
{ printf("请您输入该学生的新姓名:");
gets(newtemp);
system("cls");
printf("\a\n\n\n\n\t\t\t确定要把姓名为%s的学生修改为%s码?(y/n)",temp,newtemp);
ch=getch();
if(ch=='y'||ch=='Y')
{ strcpy(p_student[i].student.name,newtemp); //修改姓名
infofile=fopen(filename,"w+b"); //重新写入文件
for(i=0;i<count;i++)
{ if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)==1)
continue;
else
{ fclose(infofile);
printf("修改失败,返回重新操作.....");
getch();
free(temp);
free(newtemp);
system("cls");
return ; }
}
fclose(infofile);
system("cls");
printf("\n\n\n\n\t\t\t已成功把%s修改为%s返回!",temp,newtemp);
getch();
free(temp);
free(newtemp);
system("cls");
return ; }
}
}
printf("找不到%s的个人信息,返回重新操作!",temp);
free(temp);
free(newtemp);
getch();
system("cls");
return ; }
printf("\n\n\n\n\t\t\t输入有误,请返回重新操作!");
getch();
free(temp);
free(newtemp);
system("cls");
return ;
}
/************************修改个人性别*********************/
void mofsex(struct allstudentinfo *p_student)
{ char *tempname; //要修改的学生的名字
char *tempsex; //要修改的学生的性别
char ch;
int count;
int i;
system("cls");
count=datfile(p_student); //处理文件
if(!count)
{ printf("读取数据失败,请确认已成功录入数据或文件是否损坏!");
getch();
return ; }
tempname=(char *)malloc(10*sizeof(char)); //分配内存
tempsex=(char *)malloc(10*sizeof(char)); //分配内存
printf("请输入要修改的学生姓名:");
while(gets(tempname)!=NULL&&tempname[0]!='\0')
{
for(i=0;i<count;i++)
{ if(strcmp(tempname,p_student[i].student.name))
continue;
else
{ printf("请输入该学生的新性别:");
gets(tempsex);
system("cls");
printf("\a\n\n\n\n\t\t\t确定要修改该学生的性别吗?(y/n)");
ch=getch();
if(ch=='y'||ch=='Y')
{ strcpy(p_student[i].student.sex,tempsex);
infofile=fopen(filename,"w+b");
for(i=0;i<count;i++)
{ if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)==1)
continue;
else
{ fclose(infofile);
system("cls");
printf("\n\n\n\n\t\t\t修改失败,请返回.....");
getch();
free(tempname);
free(tempsex);
system("cls");
return ; }
}
fclose(infofile);
system("cls");
printf("\n\n\n\n\t\t\t已成功修改%s的性别,返回!",tempname);
getch();
free(tempname);
free(tempsex);
system("cls");
return ; }
printf("该操作已衩取消,返回.....");
free(tempname);
free(tempsex);
getch();
system("cls");
return ; }
}
printf("找不到%s的个人信息,返回......",tempname);
free(tempname);
free(tempsex);
getch();
system("cls");
return ; }
printf("输入有误,请返回重新输入!");
free(tempname);
free(tempsex);
getch();
system("cls");
return ;}
/**************************修改旷课日期***************************/
void mofbirth(struct allstudentinfo *p_student)
{ char *tempname;
char *tempbirth;
char ch;
int i,count;
system("cls");
count=datfile(p_student); //处理文件
if(!count)
{ printf("读取数据失败,请确认已成功录入或数据是否损坏!");
getch();
return ; }
tempname=(char *)malloc(20*sizeof(char));
tempbirth=(char *)malloc(20*sizeof(char)); //分配内存
printf("请输入要修改的学生姓名:");
while(gets(tempname)!=NULL&&tempname[0]!='\0')
{ for(i=0;i<count;i++)
{ if(strcmp(tempname,p_student[i].student.name))
continue;
else
{ printf("请重新输入该学生的旷课日期:");
gets(tempbirth);
system("cls");
printf("\a\n\n\n\n\t\t\t确定要修改%s的旷课日期吗?(y/n)",tempname);
ch=getch();
if(ch=='y'||ch=='Y')
{ strcpy(p_student[i].student.kdays,tempbirth);
infofile=fopen(filename,"w+b");
for(i=0;i<count;i++)
{ if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)==1)
continue;
else
{ fclose(infofile);
free(tempname);
free(tempbirth);
system("cls");
printf("\n\n\n\n\t\t\t修改失败,返回......");
getch();
system("cls");
return ; }
}
fclose(infofile);
system("cls");
printf("\n\n\n\n\t\t\t成功修改%s的旷课日期,返回!,",tempname);
free(tempname);
free(tempbirth);
getch();
system("cls");
return ;
}
printf("\n\n\n\n\t\t\t该操作已被取消,返回!");
free(tempname);
free(tempbirth);
getch();
system("cls");
return ;
}
}
printf("\n\n\n\n\t\t\t找不到%s的个人信息,返回!",tempname);
free(tempname);
free(tempbirth);
getch();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -