C语言链表问题(简单)

来源:百度知道 编辑:UC知道 时间:2024/06/30 18:47:21
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define LEN sizeof(struct student)

struct student
{
char num[5];
float score;
struct student *next;
};
struct student *creat(void)
{
struct student *head=NULL,*net,*tail;int count=0;
for(;;)
{net=(struct student *)malloc(LEN);
printf("Input the number of student No. %d(5 bytes):",count+1);
scanf("%5s",net->num);
if(strcmp(net->num,"end")==0)
{free(net);break;}
printf("Input the score of the student %d :",count+1);
scanf("%f",&net->score);
count++;
if(count==1)
tail=head=net;
else
{
tail->next=net;
tail=net;
}
}
net->next=NULL;
return(head);

}

struct student *delist(struct student *head,char num[])
{<

将creat(void) 中的倒数第二行作下修改
// net->next=NULL;
tail->next=NULL;

我把for循环加了条件简单试了下,可以通过啊
if(head=NULL) 有点小错误head==null

太长了,看不下去,但是出现这种问题一般是把地址当变量名用了,你再仔细看一下