简单链表输出,不知道这样写哪里错了?
#include <stdio.h>struct st
{
char name[20];
int n;
float score;
struct st *next;
};
int main()
{
struct st *head=NULL;
struct st *tail=NULL;
head=malloc(sizeof(struct st*));
if(head==NULL)
return -1;
struct st* s1={"zhangyiyi",5324,98.5,NULL};
struct st* s2={"Liulili",32121,78.5,NULL};
struct st* s3={"Hufang",45221,86.0,NULL};
struct st* s4={"cuichen",21243,89.0,NULL};
head=&s1;
s1.next=&s2;
s2.next=&s3;
s3.next=&s4;
s4.next=NULL;
struct st *p=head;
while(p!=NULL)
{
printf("%s,%d,%.1f\n",p->name,p->n,p->score);
p=p->next;
}
return 0;
}
创建一个链表,里面有任意4个学生的固定信息(非动态输入),怎么把他们的信息输出?