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.
pzc/删除学生信息、查询信息.c

137 lines
3.6 KiB

void reduce()
{
int i=0,j,k,id;
FILE *fp1,*fp2,*ff;
ff=fopen("b.txt","r");
fscanf(ff,"%d",&j);
close(ff);
if((fp1=fopen("a.txt","r"))==NULL)
{
printf("file open error");
exit(0);
}
printf("请输入要删除学生信息的学号\n");
scanf("%d",&id);
while(!feof(fp1))
{
fscanf(fp1,"%d%d%s%d%d%d%d",&student[i].id,&student[i].class,&student[i].name,&student[i].time_beginhour,&student[i].time_beginminute,&student[i].time_endhour,&student[i].time_endminute);
i++;
j=i;
}
fclose(fp1);
for(i=0;i<=j;i++)
{
if(student[i].id==id)
k=i;
}
fp2=fopen("a.txt","w");
if(k==0)
{
for(i=1;i<=j;i++)
fprintf(fp2,"%d%d%s%d%d%d%d",student[i].id,student[i].class,student[i].name,student[i].time_beginhour,student[i].time_beginminute,student[i].time_endhour,student[i].time_endminute);
}
if(k>0)
{
for(i=0;i<k;i++)
fprintf(fp2,"%d%d%s%d%d%d%d",student[i].id,student[i].class,student[i].name,student[i].time_beginhour,student[i].time_beginminute,student[i].time_endhour,student[i].time_endminute);
for(i=(k+1);i<=j;i++)
fprintf(fp2,"%d%d%s%d%d%d%d",student[i].id,student[i].class,student[i].name,student[i].time_beginhour,student[i].time_beginminute,student[i].time_endhour,student[i].time_endminute);
}
fclose(fp2);
ff=fopen("b.txt","w");
fprintf(ff,"%d",j-1);
fclose(ff);
printf("删除成功");
}
void classfind()
{
FILE *fp;
int class,i=0,j;
if((fp=fopen("a.txt","r"))==NULL)
{
printf("file open error");
exit(0);
}
printf("请输入要查找的班级\n");
scanf("%d",&class);
while(!feof(fp))
{
fscanf(fp,"%d%d%s%d%d%d%d",&student[i].id,&student[i].class,&student[i].name,&student[i].time_beginhour,&student[i].time_beginminute,&student[i].time_endhour,&student[i].time_endminute);
i++;
j=i;
}
for(i=0;i<=j;i++)
{
if(student[i].class==class)
{
printf("学号;%d\n",student[i].id);
printf("班级;%d\n",student[i].class);
printf("姓名;%s\n",student[i].name);
printf("开始上机时间;%d:%d\n",student[i].time_beginhour,student[i].time_beginminute);
printf("结束上机时间;%d:%d\n",student[i].time_endhour,student[i].time_endminute);
}
}
fclose(fp);
}
void idfind()
{
int id,i=0,j;
FILE *fp;
if((fp=fopen("a.txt","r"))==NULL)
{
printf("file open error");
exit(0);
}
printf("请输入要查找的学号\n");
scanf("%d",&id);
while(!feof(fp))
{
fscanf(fp,"%d%d%s%d%d%d%d",&student[i].id,&student[i].class,&student[i].name,&student[i].time_beginhour,&student[i].time_beginminute,&student[i].time_endhour,&student[i].time_endminute);
i++;
j=i;
}
for(i=0;i<=j;i++)
{
if(student[i].id==id)
{
printf("学号;%d\n",student[i].id);
printf("班级;%d\n",student[i].class);
printf("姓名;%s\n",student[i].name);
printf("开始上机时间;%d:%d\n",student[i].time_beginhour,student[i].time_beginminute);
printf("结束上机时间;%d:%d",student[i].time_endhour,student[i].time_endminute);
}
}
fclose(fp);
}
void namefind()
{
FILE *fp;
int i=0,j;
char name[10];
if((fp=fopen("a.txt","r"))==NULL)
{
printf("file open error");
exit(0);
}
printf("请输入要查找的姓名\n");
scanf("%s",&name);
while(!feof(fp))
{
fscanf(fp,"%d%d%s%d%d%d%d",&student[i].id,&student[i].class,&student[i].name,&student[i].time_beginhour,&student[i].time_beginminute,&student[i].time_endhour,&student[i].time_endminute);
i++;
j=i;
}
for(i=0;i<=j;i++)
{
if(strcmp(student[i].name,name)==0)
{
printf("学号;%d\n",student[i].id);
printf("班级;%d\n",student[i].class);
printf("姓名;%s\n",student[i].name);
printf("开始上机时间;%d:%d\n",student[i].time_beginhour,student[i].time_beginminute);
printf("结束上机时间;%d:%d",student[i].time_endhour,student[i].time_endminute);
}
}
fclose(fp);
}