一个c语言问题,通过编译却在输出时崩溃

include
#include

struct student
{
int num;
char name[20];
int score;
struct student * next;
};

int main(void)
{
struct student * p[4];

int i;

//构建链表
p[0] = (struct student *)malloc(sizeof(struct student));
scanf("%d%s%d", &p[0]->num, p[0]->name, &p[0]->score);

for(i = 1; i < 4; ++i){
    p[i] = (struct student *)malloc(sizeof(struct student));
    scanf("%d%s%d", &p[i]->num, p[i]->name, &p[i]->score);
    p[i - 1]->next = p[i];
}

p[i]->next = NULL;

//输出链表
printf("NO.%d name:%s score: %d\n", p[0]->num, p[0]->name, p[0]->score);

for(i = 1; i < 4; ++i){
    p[i] = p[i - 1]->next;
    printf("NO.%d name: %s score: %d\n", p[i]->num, p[i]->name, p[i]->score);
}

return 0;

}

c

1个回答

p[i]->next = NULL; 去掉就okay~

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐