malloc_ze 2017-01-04 10:17 采纳率: 0%
浏览 936

求大神帮我看下这段程序,运行到“输入第二个学生姓名”就崩溃了。

#include
#include
struct student
{
int age;
char name[40];
float score;
};

void intput(struct student **st, int len);
void output(struct student **st, int len);

int main (void)
{
int len;
printf("请输入学生人数:");
scanf("%d", &len);
struct student * st = (struct student*)malloc(sizeof(struct student) * len);
intput(&st, len);
output(&st, len);

return 0;

}

void intput(struct student **st, int len)
{
int i;
for (i=0; i {
printf("请输入第%d个人的姓名:", i+1);
scanf("%s", &st[i]->name);
printf("请输入第%d个人的年龄:", i+1);
scanf("%d", &st[i]->age);
printf("请输入第%d个人的分数:", i+1);
scanf("%f", &st[i]->score);
}
}

void output(struct student **st, int len)
{
int i;
for (i=0; i {
printf("第%d个人的信息:\n", i+1);
printf("姓名:%s\n", st[i]->name);
printf("年龄:%d\n", st[i]->age);
printf("分数:%f\n", st[i]->score);
}
}

  • 写回答

3条回答

  • YXTS122 2017-01-04 10:30
    关注

    这程序没必要用到二级指针吧?intput(st,len);这样不是很好么?

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog