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

取消对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 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题