c语言的应用以及未来发展 c语言学生信息管理系统代码( 二 )


/*修改记录*/
void modify()
{
int k=0;
long position;
char nokey[10];
struct student stu;
printf(“\n请输入学号:”);
scanf(“%s”,nokey);
if((fp=fopen(filename,”r ”))==NULL)
{
printf(“\nCannot Open File!”);
exit(0);
}
fseek(fp,1L*sizeof(struct student),0);
while(!feof(fp))
{
fscanf(fp,”%s%s%d”,stu.no,stu.name,&stu.score);
if(strcmp(nokey,stu.no)==0)
{ position=ftell(fp);
k=1;
break;
}
}
if(k)
{
printf(“\n\n已查找到 , 该记录为:\n\n”);
printf(“%-10s%-20s%-50s”,”学号”,”姓名”,”成绩”);
printf(“%-10s%-20s%-50d”,stu.no,stu.name,stu.score);
printf(“\n请输入新的学号、姓名及成绩:”);
scanf(“%s%s%d”,stu.no,stu.name,&stu.score);
fseek(fp,position-1L*sizeof(struct student),SEEK_SET);
fprintf(fp,”\n%-10s%-20s%-50d”,stu.no,stu.name,stu.score);
}
else
printf(“\n\n文件中无此人的记录 。”);
fclose(fp);
}
/*删除记录*/
void del()
{
int m,k=0;
long position;
char nokey[10];
struct student stu;
【c语言的应用以及未来发展 c语言学生信息管理系统代码】printf(“\n请输入学号:”);
scanf(“%s”,nokey);
if((fp=fopen(filename,”r ”))==NULL)
{
printf(“\nCannot Open File!”);
exit(0);
}
fseek(fp,1L*sizeof(struct student),0);
while(!feof(fp))
{
fscanf(fp,”%s%s%d”,stu.no,stu.name,&stu.score);
if(strcmp(nokey,stu.no)==0)
{ position=ftell(fp);
k=1;
break;
}
}
if(k)
{
printf(“\n\n已查找到 , 该记录为:\n\n”);
printf(“%-10s%-20s%-50s”,”学号”,”姓名”,”成绩”);
printf(“%-10s%-20s%-50d”,stu.no,stu.name,stu.score);
printf(“\n确实要删除记录 , 请按1;不删除记录 , 请按0:”);
scanf(“%d”,&m);
if(m)
{
fseek(fp,position-1L*sizeof(struct student),SEEK_SET);
fprintf(fp,”%-10s%-20s%-50s”,””,””,””);
}
}
else
printf(“\n\n文件中无此人的记录 。”);
fclose(fp);
}
/*显示记录*/
void output()
{
struct student stu;
if((fp=fopen(filename,”r”))==NULL)
{
printf(“\nCannot Open File!”);
exit(0);
}
printf(“\n\n文件内容为:\n”);
fseek(fp,1L*sizeof(struct student),0);
while(!feof(fp))
{
fscanf(fp,”%s%s%d\n”,stu.no,stu.name,&stu.score);
printf(“%-10s%-20s%-50d”,stu.no,stu.name,stu.score);
}
fclose(fp);
}