诗岑 2020-02-19 19:58 采纳率: 93%
浏览 4732
已采纳

取消对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”的引用。

  • 写回答

4条回答 默认 最新

  • QiQaWgYu 2020-02-19 23:24
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog