c链表居然程序错误

来源:百度知道 编辑:UC知道 时间:2024/05/15 09:11:21
可编译,但微软会弹出程序错误
3. 建立一个链表,每个结点包括:学号、姓名、性别、年龄。输入一个年龄,如果链表中的结点所包含的年龄等于此年龄,则将此结点删去。

#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct student)
struct student
{long num;
char name[20];
char sex;
int age;
struct student *next;
};

struct student *del(struct student *head,int age)
{
struct student *pd,*pn;
if(head==NULL)return NULL;
else{
pd=head;
while(pd->next!=NULL&&age!=pd->age)
{pn=pd;
pd=pd->next;}
if(pd->age==age)
{if(pd==head) head=pd->next;
else pn->next=pd->next;}
}
return head;
}

int main()
{
struct student *head;
struct student *p1,*p2;
int n;

起码要说明是什么错误吧?20分还不到差错。

struct student *del(struct student *head,int age) 函数体写错了, 仅当只有一个元素,且头结点为要找的目标, 就会出错 自己调试下吧.