}
SortInfor(STUDENT stu[],int Max,char i)
{
STUDENT student;
int j=0,k,l=0;
if(i=='1')
{
for(k=0;j<Max;j++)
for(;k<Max-j-1;k++)
{
if(stu[k].ID>stu[k+1].ID)
{
student.ID=stu[k+1].ID;
strcpy(student.Name,stu[k+1].Name);
student.Age=stu[k+1].Age;
strcpy(student.Sex,stu[k+1].Sex);
student.Birthday=stu[k+1].Birthday;
strcpy(student.Adress,stu[k+1].Adress);
strcpy(student.TelNum,stu[k+1].TelNum);
strcpy(student.Email,stu[k+1].Email);
stu[k+1].ID=stu[k].ID;
strcpy(stu[k+1].Name,stu[k].Name);
stu[k+1].Age=stu[k].Age;
strcpy(stu[k+1].Sex,stu[k].Sex);
stu[k+1].Birthday=stu[k].Birthday;
strcpy(stu[k+1].Adress,stu[k].Adress);
strcpy(stu[k+1].TelNum,stu[k].TelNum);
strcpy(stu[k+1].Email,stu[k].Email);
stu[k].ID=student.ID;
strcpy(stu[k].Name,student.Name);
stu[k].Age=student.Age;
strcpy(stu[k].Sex,student.Sex);
stu[k].Birthday=student.Birthday;
strcpy(stu[k].Adress,student.Adress);
strcpy(stu[k].TelNum,student.TelNum);
strcpy(stu[k].Email,student.Email);
}
printf("\n 学号 姓名 年龄 性别 出生年月\t 地址\t 电话\t E-mail\n");
for(i=0;i<Max;i++)
printf("%8d %10s %2d %2s %8d %15s %12s %10s",stu[i].ID,stu[i].Name,stu[i].Age,stu[i].Sex,stu[i].Birthday,stu[i].Adress,stu[i].TelNum,stu[i].Email);
printf("\n");
}
}
else if(i=='2')
{
for(k=0;j<Max;j++)
for(;k<Max-j-1;k++)
{
if(strcmp(stu[k].Name,stu[k+1].Name)>0)
{
student.ID=stu[k+1].ID;
strcpy(student.Name,stu[k+1].Name);
student.Age=stu[k+1].Age;
strcpy(student.Sex,stu[k+1].Sex);
student.Birthday=stu[k+1].Birthday;
strcpy(student.Adress,stu[k+1].Adress);
strcpy(student.TelNum,stu[k+1].TelNum);
strcpy(student.Email,stu[k+1].Email);
stu[k+1].ID=stu[k].ID;
strcpy(stu[k+1].Name,stu[k].Name);
stu[k+1].Age=stu[k].Age;
strcpy(stu[k+1].Sex,stu[k].Sex);
stu[k+1].Birthday=stu[k].Birthday;
strcpy(stu[k+1].Adress,stu[k].Adress);
strcpy(stu[k+1].TelNum,stu[k].TelNum);
strcpy(stu[k+1].Email,stu[k].Email);
stu[k].ID=student.ID;
strcpy(stu[k].Name,student.Name);
stu[k].Age=student.Age;
strcpy(stu[k].Sex,student.Sex);
stu[k].Birthday=student.Birthday;
strcpy(stu[k].Adress,student.Adress);
strcpy(stu[k].TelNum,student.TelNum);
strcpy(stu[k].Email,student.Email);
}
}
printf("\n 姓名 学号 年龄 性别 出生年月\t 地址\t 电话\t E-mail\n");
for(;l<Max;l++)
printf("%10s %8d %2d %2s %8d %15s %12s %10s",stu[l].Name,stu[l].ID,stu[l].Age,stu[l].Sex,stu[l].Birthday,stu[l].Adress,stu[l].TelNum,stu[l].Email);
printf("\n");
}
}
Save(STUDENT stu[],int Max)
{
int i=0 ;
FILE *fp;
if((fp=fopen("stu.txt","w+"))==NULL)
{
printf("ERROR!");
exit(0);
}
for(;i<Max;i++)
{
fprintf(fp,"%d ",stu[i].ID);
fprintf(fp,"%s ",stu[i].Name);
fprintf(fp,"%d ",stu[i].Age);
fprintf(fp,"%s ",stu[i].Sex);
fprintf(fp,"%d ",stu[i].Birthday);
fprintf(fp,"%s ",stu[i].Adress);
fprintf(fp,"%s ",stu[i].TelNum);
fprintf(fp,"%s ",stu[i].Email);
}
fclose(fp);
printf("OK!");
}
int main(int argc, char *argv[])
{
char select;
STUDENT stu[MAX_NUM];
int current_number=0;
select=0;
while(select!='0')
{
system("cls");
DispMainMenu();
select=choice();
switch(select)
{
case '0':
printf("\n您选择的是退出测试!\n");
_beep(300,400);
continue;
case '1':
printf("\n您选择的是信息录入!\n");
current_number=InforInput(stu,current_number);
break;
case '2':
printf("\n您选择的是信息修改!\n");
EditInfor(stu,current_number);
break;
case '3':
printf("\n您选择的是信息查询!\n");
QueryInfor(stu,current_number);
break;
case '4':
printf("\n您选择的是删除信息!\n");
DelInfor(stu,current_number);
break;
case '5':
printf("\n您选择的是排序信息!\n");
SortInforMenu(stu,current_number);
break;
default:
printf("\n选择错误!请重新选择!\n");
}
system("PAUSE");
}
return (0);
Save(stu,current_number);
}