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.
67 lines
2.0 KiB
67 lines
2.0 KiB
#include"主函数.c"
|
|
void refresh()/*将文件中学生的信息导入*/
|
|
{
|
|
FILE *fp;
|
|
int i=0;/*计算导入学生的个数*/
|
|
if((fp=fopen("student.txt","r"))==NULL)
|
|
{
|
|
printf("cannot open the file");
|
|
system("pause");
|
|
exit(0);/*如未能打开直接退出程序*/
|
|
}
|
|
while(fscanf(fp,"%s %s %d %s %s %s %s %s",stu[i].id,stu[i].name,&stu[i].age,stu[i].sex,stu[i].birth,stu[i].add,stu[i].tel,stu[i].email)!=EOF)
|
|
i++;
|
|
n=i;
|
|
if(fclose(fp))/*检测是否将文件关闭*/
|
|
{
|
|
printf("cannot close the file");
|
|
exit(0);
|
|
}
|
|
printf("刷新完成\n");
|
|
}
|
|
void seek()/*查找函数*/
|
|
{
|
|
int i,num,flag;
|
|
char ch[LEN+1];/*用于存放查询学生的姓名或名字*/
|
|
printf("**************\n");
|
|
printf("1:按学号查询\n");
|
|
printf("2:按姓名查询\n");
|
|
printf("3:退出本次查询\n");
|
|
printf("**************\n");
|
|
while(1)
|
|
{
|
|
printf("请输入编号:");
|
|
scanf("%d",&num);
|
|
flag=0;
|
|
switch(num)
|
|
{
|
|
case 1: printf("请输入要查询的学生的学号:");
|
|
scanf("%s",ch);
|
|
for(i=0;i<n;i++)
|
|
if(strcmp(stu[i].id,ch)==0)
|
|
{
|
|
flag=1;
|
|
printf("学生学号 学生姓名 年龄 性别 出生年月 地址 电话 E-mail\n");
|
|
printf("-------------------------------------------------------------------------------\n");
|
|
printf("%6s %6s %5d %5s %9s %8s %10s %14s\n",stu[i].id,stu[i].name,stu[i].age,stu[i].sex,stu[i].birth,stu[i].add,stu[i].tel,stu[i].email);
|
|
}
|
|
if(flag==0)
|
|
printf("学号不存在\n");break;
|
|
case 2: printf("请输入要查询学生的姓名:");
|
|
scanf("%s",ch);
|
|
for(i=0;i<n;i++)
|
|
if(strcmp(stu[i].name,ch)==0)
|
|
{
|
|
flag=1;
|
|
printf("学生学号 学生姓名 年龄 性别 出生年月 地址 电话 E-mail\n");
|
|
printf("-------------------------------------------------------------------------------\n");
|
|
printf("%6s %6s %5d %5s %9s %8s %10s %14s\n",stu[i].id,stu[i].name,stu[i].age,stu[i].sex,stu[i].birth,stu[i].add,stu[i].tel,stu[i].email);
|
|
}
|
|
if(flag==0)
|
|
printf("姓名不存在\n");break;
|
|
case 3: return;
|
|
default:printf("只能在1-3中选择\n");
|
|
}
|
|
}
|
|
}
|