scanf错误,&非法???
程序代码:/*
2017年3月19日 18:03:28
建立一个动态链表,
各个结点由用户输入
学号为0表示输入结束
*/
# include<stdio.h>
# include<stdlib.h>
# define LEN sizeof(struct Student)
//sizeof函数是取得括号内数据类型的长度,比如vc中int类型为4;
//这里是定义一个常量LEN,他的值是sizeof的函数返回值;
struct Student //定义一个数据类型
{
int num;
float score;
struct Student * next;
};
int n; //定义一个全局变量n
struct Student * creat(void)
//定义一个指针函数,返回一个函数值为struct Student类型的地址,不接收参数
{
struct Student * head;
struct Student * p1, *p2;
n = 0; //前面已经定义了一个n,所以直接赋值
p1 = p2 = (struct Student *)malloc(LEN); //为struct Student类型分配一个存储单元
scanf("%d,%f," &p1->num, &p1->score); //输入一个学生的学号和成绩
head = NULL; //头指针为零
while(p1->num != 0) //如果输入学号为0,则指针指向NULL
{
n = n+1;
if(n == 1)
head = p1; //head是头指针
else
p2->next = p1; //p2->next指向了p1
p2 = p1; //
p1 = (struct Student *)malloc(LEN);
scanf("%d,%f", &p1->num, &p1->score);
}
p2->next = NULL;
return (head);
}
int main(void)
{
struct Student * pt;
pt = creat();
printf("\nnum:%d\nscore:%5.1f\n", pt->num, pt->score);
return 0;
}








