st[j+1]=temp;
}
printf("=========================================\n");
printf("%-10s\t%-8s\t%3s\n","ID","NAME","SCORE");
for(i=0;i<n;i++){
printf("%-10s\t%-8s\t%3d\n",st[i].id,st[i].name,st[i].score);
}
printf("=========================================\n");
getch();
}
}
STU *check(void){
FILE *fp;
STU *head;
int n;
fp=fopen("c:\\check.txt","r");
if(fp==NULL){
fp=fopen("c:\\check.txt","w");
fprintf(fp,"%d",0);
fclose(fp);
fp=fopen("c:\\check.txt","r");
}
fscanf(fp,"%d",&n);
fclose(fp);
n++;
if(n==1){
printf("first time to use.please input data\n");
getch();
system("cls");
head=creat();
fp=fopen("c:\\check.txt","w");
fprintf(fp,"%d",n);
fclose(fp);
return head;
}
head=datain();
fp=fopen("c:\\check.txt","w");
fprintf(fp,"%d",n);
fclose(fp);
return head;
}
int main(){
STU *head=NULL,*pNew;
char temp[20];
int choice;
system("title Admin");
head=check();
for(;;){
system("cls");
printf("================================\n");
printf("1.display\n");
printf("2.insert\n");
printf("3.del\n");
printf("4.search\n");
printf("5.display by score\n");
printf("6.exit and save\n");
printf("================================\n");
printf("choice:");
scanf("%d%*c",&choice);
switch(choice){
case 1:display(head);break;
case 2:pNew=(STU *)malloc(LEN);
printf("id:");
gets(temp);
pNew->id=(char *)malloc(strlen(temp)+1);
strcpy(pNew->id,temp);
printf("name:");
gets(temp);
pNew->name=(char *)malloc(strlen(temp)+1);
strcpy(pNew->name,temp);
printf("score:");
scanf("%d%*c",&pNew->score);
head=insert(head,pNew);
break;
case 3:printf("input the id you wanna del:");
gets(temp);
head=del(head,temp);
break;
case 4:printf("input the id you wanna search:");
gets(temp);
search(head,temp);
break;
case 5:sort(head);
break;
default:save(head);
exit(0);
}
}
getch();
return 0;
}