#define SIZE 2
struct stud_sub
{
char name[10];
char grade[10];
char college[10];
char zhuanye[10];
}sub[SIZE];
void save()
{
FILE*fp;
int i;
if((fp=fopen("sub_list","wb"))==NULL)
{
printf("cannot open file\n");
return;
}
for(i=0;i<SIZE;i++)
{
printf("please enter the mat collations:\n");
scanf("%s%s%s%s%s",sub[i].name,sub[i].col_stud,sub[i].college,sub[i].zhuanye);
}
fclose(fp);
}
void check()
{
int i,j,m,n;
char a[10],b[10],c[10],d[10];
FILE*fp;
printf("please enter four charactors:\n");
scanf("%s%s%s%s",a,b,c,d);
fp=fopen("sub_list","rb");
for(i=0;i<SIZE;i++)
{
fread(&sub[i],sizeof(struct stud_sub),1,fp);
m=(strcmp(sub[i].col_stud,a))||(strcmp(sub[i].grade,b));
n=(strcmp(sub[i].college,c))||(strcmp(sub[i].zhuanye,d));
j=n||m;
if(!j)
{
printf("the subject name:\n");
printf("%s\n",sub[i].name);
}
}
fclose(fp);
}
void change()
{
int i;
char a[10],b[10],c[10];
FILE*fp;
printf("please enter the subject name:\n");
scanf("%s",a);
fp=fopen("sub_list","rb");
for(i=0;i<SIZE;i++)
{ fread(&sub[i],sizeof(struct stud_sub),1,fp);
if(!strcmp(sub.name,a))
{
printf("the four charactors are:\n");
printf("%s%s%s%s\n",sub[i].col_stud,sub[i].grade,sub[i].college,sub[i].zhuanye);
printf("please input what you want to change:b and c:\n");
scanf("%s%s",b,c);
strcpy(sub[i].college,b);
strcpy(sub[i].college,c);
}
}
save();
}
viod run()
{
char a[10]="check",b[10]="change",m[10];
printf("what do you want to do?please enter check or change:\n");
scanf("%s",m);
if(!strcmp(a,m))
{
printf("checking begin:\n");
check();
}
if(!srtcmp(b,m))
{
printf("changing begin:\n");
change();
}
}
main()
{
if(fopen("sub_list","rb")==NULL)
make();
else run();
}