取消对NUll指针的引用

如题,而且运行过后它一直在输入也不输出

#include<stdio.h>
#include<stdlib.h>
struct student {
    char name[20];
    int score;
    struct student* pnext;//指向下一个学生的指针
};
int count=0;
struct student* create() {
    struct student *phead = NULL;
    struct student* pend, * pnew;
    pend = (struct student*)malloc(sizeof(struct student));
    pnew = (struct student*)malloc(sizeof(struct student));
    scanf_s("%s", &pnew->name, 20);
    scanf_s("%d", &pnew->score);
    while (pnew->score != 0) {
        count++;
        if (count == 1) {
            pend = pnew;
            phead = pnew;
        }
        else {
            pnew->pnext = NULL;
            pend->pnext = pnew;
            pend = pnew;
        }
        pnew = (struct student*)malloc(sizeof(struct student));
        scanf_s("%s", &pnew->name, 20);
        scanf_s("%d", &pnew->score);

    }
    free(pnew);
    return phead;


}
void print(struct student* phead) {
    struct student *ptemp;
    int index = 1;
    ptemp = phead;
    while (ptemp != NULL) {
        printf("%s\n", ptemp->name);
        printf("%d\n", ptemp->score);
        ptemp = ptemp->pnext;
        index++;
    }

}
main() {
    struct student* phead;
    phead = create();
    print(phead);
    return 0;
}

取消对 NULL 指针“pend”的引用。查看第 14 行以找出可能会发生此情况的前一位置
取消对 NULL 指针“pnew”的引用。

啥意思,有输出呀
图片说明

你可以试试在你申请动态存储空间的时候判断一下你的返回值是不是NULL,取消对 NULL 指针“pend”的引用。
取消对 NULL 指针“pnew”的引用
这两个信息的意思是pend和pnew可能是NULL

https://blog.csdn.net/DZRYWYBL/article/details/102942556

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^