链表的知识,定义了一个结构体数组,想删除链表中的第一个结构体元素,下面的函数怎么不行??
鬼鬼先生 2013-04-10 12:34:48 void Delete(struct student *head)
{
system("cls");
int exit=0;
char s[5];
printf("输入要删除学生的学号:(如果删除所有学生请输入0000)\n学号:");
scanf("%s",s);
while(!exit){
if(strlen(s)!=4){
printf("输入非法:学号必须是4位,请重新输入!\n");
scanf("%s",s);}
else
exit=1;
}
struct student *p1,*p2;
if(head==NULL)
{
printf("\nthe list is null!\n");
}
p1=head;
while(strcmp(p1->ID,s)!=0&&p1->next!=NULL){
p2=p1;
p1=p1->next;
}
if(strcmp(p1->ID,s)==0){
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
free(p1);
iTotal--;
printf("%s的学生成功删除\n",s);
}
else
printf("没有找到学号为 %s 的学生,请确认学号输入是否正确!\n",s);
printf("press any key to continue ");
getch();
}