###### xg丶pilot

2018-12-08 04:29 阅读 404

# 大佬帮忙看下代码哪里错了

#include
#include
#include
struct student
{
int score;
int num;
struct student *next;
};
struct student *chain(int n)
{
int i;
struct student *head = NULL, *p1 = NULL, *p2 = NULL;
for(i=1;i<=n;i++)
{
if ((p1 = (struct student *)malloc(sizeof(struct student))) == NULL)
{
printf("分配失败");
exit(0);
}
if (i >= 2)p2->next = p1;
p2 = p1;
}
}
void input(int n, struct student *head)
{
int i;
for (i = 1; i <= n; i++)
{
printf("请输入第%d个同学的学号和成绩",i);
printf("1");
printf("2");
printf("3");
}
}
void output(int n, struct student *head)
{
int i;
for (i = 1; i <= n; i++)
{
}
}
int main()
{
int n;
printf("请输入学生个数n=:");
scanf("%d", &n);
return 0;
}

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享

• 已采纳

# 采纳的方法是点我回答左上角的采纳和向上的箭头。谢谢

``````#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>

struct student
{
int score;
int num;
struct student *next;
};
struct student *chain(int n)
{
int i;
struct student *head = NULL, *p1 = NULL, *p2 = NULL;
for(i=1;i<=n;i++)
{
if ((p1 = (struct student *)malloc(sizeof(struct student))) == NULL)
{
printf("分配失败");
exit(0);
}
p1->next = NULL;
if (i >= 2)p2->next = p1;
p2 = p1;
}
}
void input(int n, struct student *head)
{
int i;
for (i = 1; i <= n; i++)
{
printf("请输入第%d个同学的学号和成绩",i);
//printf("1");
//printf("2");
//printf("3");
}
}
void output(int n, struct student *head)
{
int i;
for (i = 1; i <= n; i++)
{
}
}
int main()
{
int n;