#includestdio.h
#includestring.h
#includemalloc.h
structDate{
intYear;
intMonth;
intDay;
};
structScore{
floatA;
floatB;
floatC;
floatALL;
};
structstudent{
intnum;
charname[20];
charsex;
structDateBirth;
structScoreS;
structstudent*next;
};
structstudentsave(structstudent*head)
{
structstudent*p1,*p2;
p1=p2=head;
FILE*fp;
if((fp=fopen(\"student_list.txt\",\"w\"))==NULL)
printf(\"cannotopenfile\\n\");
while(p2-next!=NULL)
{
fprintf(fp,\"%d%s%c%d%d%d%f%f%f\",p1-num,p1-name,p1-sex,p1-Birth.Year,p1-Birth.Month,p1-Birth.Day,p1-S.A,p1-S.B,p1-S.C);
p2=p1;
p1=p2-next;
}
printf(\"数据写入完成!\");
fclose(fp);
return*head;
}
structstudentoutput(structstudent*head)
{
head=NULL;
FILE*fp;
if((fp=fopen(\"student_list.txt\",\"r\"))==NULL)
{printf(\"cannotopenfile\\n\");return*head;}
structstudent*p1,*p2;
p1=p2=(structstudent*)malloc(sizeof(structstudent));
fread(p1,sizeof(structstudent),1,fp);
while(!feof(fp))
{
if(head==NULL)head=p1;
elsep2-next=p1;
p2=p1;
p1=(structstudent*)malloc(sizeof(structstudent));
fread(p1,sizeof(structstudent),1,fp);
}
p2-next=NULL;
fclose(fp);
return*head;
}
//creatnew()函数,创建新的学生信息库;
structstudentcreatnew(structstudent*head)
{
structstudent*p1,*p2;
head=NULL;
p1=(structstudent*)malloc(sizeof(structstudent));
input(p1);sum=1;
while(p1-num!=0)
{
if(head==NULL)head=p1;
elsep2-next=p1;
p2=p1;
p1=(structstudent*)malloc(sizeof(structstudent));
input(p1);sum=sum1;
}
p2-next=NULL;
save(head);
return*head;
}
|