如下题:为什么单链表不能输出了?
#include <stdio.h>
#include <malloc.h>
typedef struct stu *list;
struct stu{
char name[10];
int age;
int class_num;
struct stu *next;
};
int main(void)
{
list st1 = NULL;
list head = NULL;
list p = NULL;
int num = 0;
for(num=0; num<3; num++)
{
st1 = (struct stu *)malloc(sizeof(struct stu));
if(head == NULL)
head = st1;
printf("请输入第%d个学生的姓名:",num+1);
scanf("%s",st1->name);
printf("请输入第%d个学生的年龄:",num+1);
scanf("%d",&st1->age);
printf("请输入第%d个学生的学号:",num+1);
scanf("%d",&st1->class_num);
st1 = st1->next;
st1 = NULL;
}
printf("学生的信息输出:\n");
for(num=0; num<3; num++)
{
printf("结果统计:第%d个学生姓名是:%s\t年龄是:%d\t 学号是:%d\n",4-num, head->name, head->age, head->class_num);
/*释放链表*/
p = head;
head = head->next;
free(p);
}
return 0;
}