m0_61800796
2021-10-12 17:36
采纳率: 94%
浏览 31

c语言链表问题,从上午研究到下午,感觉还是理解不透

img

img

想问下是哪里出了问题,改来改去好几次了还是报错

#include <stdio.h>
#include <malloc.h>
typedef struct student{
int score;
struct student *next;
}list;

struct student create();
void print(list a);

int main(){
struct student *p;
p = create();
print(p);
}

struct student create(){
int i = 2;
struct student *head,*middle,end;
head = (struct student
)malloc(sizeof(struct student));
end = head;
middle = end;
printf("请输入第1个学生的分数:");
scanf("%d",&middle->score);
while(middle->score){
end->next = middle;
end = middle;
printf("请输入第%d个学生的分数:",i);
scanf("%d",&middle->score);
i++
}
end = NULL;
return head;
}

void print(struct student a){
while(a->next!=0){
printf("%d",a->next.score);
a = a->next;
}
}

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • m0_61800796 2021-10-12 17:38
    已采纳

    漏了一块

    img

    已采纳该答案
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题