/*查找记录函数*/
void search(STUDENT *head)
{STUDENT *p; /* 移动指针*/
char s[5]; /*存放姓名用的字符数组*/
clrscr();
printf("Please enter name for searching.\n");
scanf("%s",s);
p=head; /*将头指针赋给p*/
while(strcmp(p->name,s) && p != NULL) /*当记录的姓名不是要找的,或指针不为空时*/
p=p->next; /*移动指针,指向下一结点*/
if(p!=NULL) /*如果指针不为空*/
{printf("\n*************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
}
else
printf("\nThere is no num %s student on the list.\n",s); /*显示没有该学生*/
}
/*删除记录函数*/
STUDENT *delete(STUDENT *head)
{int n;
STUDENT *p1,*p2; /*p1为查找到要删除的结点指针,p2为其前驱指针*/
char c,s[6]; /*s[6]用来存放学号,c用来输入字母*/
clrscr();
printf("Please enter the deleted num: ");
scanf("%s",s);
p1=p2=head; /*给p1和p2赋初值头指针*/
while(strcmp(p1->num,s) && p1 != NULL) /*当记录的学号不是要找的,或指针不为空时*/
{p2=p1; /*将p1指针值赋给p2作为p1的前驱指针*/
p1=p1->next; /*将p1指针指向下一条记录*/
}
if(strcmp(p1->num,s)==0) /*学号找到了*/
{printf("**************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p1->num,p1->name,p1->score[0],p1->score[1],p1->score[2],p1->sum,p1->average,p1->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
printf("Are you sure to delete the student Y/N ?"); /*提示是否要删除,输入Y删除,N则退出*/
for(;;)