如题,而且运行过后它一直在输入也不输出
#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”的引用。