一个C的函数错误

来源:百度知道 编辑:UC知道 时间:2024/05/17 05:44:28
struct student *del(struct student*head,long num)
{
struct student *p1,*p2;
if(head==NULL){printf("\nlist null\n");goto end;}
p1=head;
while(num!==p1->num && p1->next!==NULL)
{
p2=p1;
p1->next;
}
if(num==p1->num)
{if(head==p1)
head=p1->next;
else p2->next=p1->next;
printf("delete:%ld\n",num);
n=n-1;
}
else printf("%ld has not been found!",num);
end;
return (head);
}

兄弟,错误真的挺多的,还是细看一下有关c语言相关的书籍。
回头给兄弟贴一个删除链表结点的c语言实现。
先指出一点,现在是没人用goto语句了(除非是为了跳出多重循环),这让代码很难读。兄弟可以将goto end; 直接替换成return (head);