修改如下,供参考对照:
#include<stdio.h>
#include<malloc.h>
typedef struct student{
int score;
struct student *next;
}list;
struct student* create(){
int i=0;
struct student *head,*middle,*end;
head = (list *)malloc(sizeof(list));
head->next = NULL;
middle = head;
while(1){
end = (list *)malloc(sizeof(list));
end->next = NULL;
printf("请输入第%d个学生的分数:",i+1);
scanf("%d",&end->score);
if(end->score == -1) break; //-1 结束输入
if(i==0)
{
head->next = end;
}
else{
middle->next = end;
}
middle = end;
i++;
}
free(end);
return head;
}
void print(struct student *a)
{
struct student *p;
p = a->next;
while(p)
{
printf("%d ",p->score);
p = p->next;
}
printf("\n");
}
int main()
{
list *p;
p = create();
print(p);
return 0;
}