求教一下关于链表的输入;
#include<stdio.h>
#include <malloc.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>
#define LEN sizeof(struct Student)
int c_num()
{
static int i = 1; int a;
a = 2019051000 + i;
i = i + 1;
return a;
}
struct Student
{
int num;
struct Student* next;
};
int n;
struct Student* creat(void)
{
struct Student* head;
struct Student* p1, * p2;
n = 0;
p1 = p2 = (struct Student*)malloc(LEN);
p1->num = 2019051110;
//scanf("%d", &p1->num);
head = NULL;
while (p1->num != 0)
{
n = n + 1;
if (n == 1)head = p1;
else p2->next = p1;
p2 = p1;
p1 = (struct Student*)malloc(LEN);
p1->num = c_num();
//scanf("%d", &p1->num);
}
p2->next = NULL;
return (head);
}
int main()
{
struct Student* pt;
pt = creat();
printf("num=%d", pt->num);
}
为什么这样会有nullptr的报错,而使用//里的scanf函数就没有问题?
请各位不吝赐教