请教一个链表的问题
程序代码:#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#define LEN sizeof(struct student)
struct student
{
long num;
float score;
struct student *next;
};
int glwd_n;
/*************************************************
Function: creat()// 函数名称
Description: 建立链表// 函数功能、性能等的描述
Calls: malloc()/scanf()/free()
// 被本函数调用的函数清单
Called By: // 调用本函数的函数清单
Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
Input: // 输入参数说明,包括每个参数的作
// 用、取值说明及参数间关系。
Output: // 对输出参数的说明。
Return: 表头// 函数返回值的说明
Others: // 其它说明
*************************************************/
struct student *creat()
{
struct student *head,*p1,*p2;
glwd_n = 0;
head = NULL;
p1 = (struct student*)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
getchar();
p1->next = NULL;
while (p1->num != 0)
{
++glwd_n;
if (glwd_n == 1) head = p1;
else p2->next = p1;
p2 = p1;
p1 = (struct student*)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
getchar();
p1->next = NULL;
}/* end of while (p1->num != 0) */ // 指明该条while语句结束
free(p1);
printf("\ncreat end\n");
return (head);
}
void main()
{
struct student *head,*stud;
head = creat();
print_list(head);
}
问题如下:
输入:01 90回车 0回车
输出结果:
print_list函数输出的内容有点奇怪,请各位帮忙看看,谢谢!









