C语言结构体,我用点不行,必须要用->才编译成功,这是为什么

#include
#include
#include
#define LEN sizeof(struct student)
struct student
{
int number;
struct student *pnext;
};
int n;
struct student *creat(void)
{
struct student *head,*p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
head=NULL;
scanf("%d",&p1.number);
while(p1.number!=0)
{
n++;
if(n==1) head=p1;
else p2->pnext=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%d",&p1.number);
}
p2->pnext=NULL;
return(head);
}
main()
{
struct student *p;
p=creat();
while(p->pnext!=NULL)
{
printf("%d\n",p->number);
p=p->pnext;
}
return 0;
}

17 17 E:\学习\C源程序\C红书刷题\第三章_结构数据\链表\创建动态链表\未命名2.cpp [Error] request for member 'number' in 'p1', which is of pointer type 'student*' (maybe you meant to use '->' ?)
这是错误提示,然后我把.改成了->就解决了。为什么要这样, 点和->作用不是一样的么

看你是不是指针,指针用->,一般变量用 .

struct student *pnext;定义的是指针要用->pnext
而int number定义的是整型变量要用.number调用

因为 你的p是一个指针

而指针结构的成员 要用->指向

看你是如何访问结构体中变量的,如果你是通过结构体指针访问,用->,如果是通过结构体名访问用 .