初学 简单的程序运行出错,求指导
# include <stdio.h># include <malloc.h>
void shuru ();
void mao ();
void shuchu ();
struct sss
{
int age;
float fenshu;
char name[100];
};
void mao (struct sss * p, int len)
{
int i, j, k = len;
struct sss t;
for (j = 0; j < len; ++j)
{
i = 0;
for (i =0; i < k-1; ++i)
{
if (p [i].fenshu > p [i + 1].fenshu)
{
t = p [i];
p [i] = p [i + 1];
p [i + 1] = t;
}
--k;
}
}
return;
}
void shuru (struct sss *p, int len)
{
int i ;
for (i = 0; i < len; ++i)
{
printf ("请输入第%d个学生的信息\n", i + 1);
printf ("学生年龄是");
scanf ("%d",&p[i].age);
printf ("\n学生分数是");
scanf ("%f",&p[i].fenshu);
printf ("\n学生名字是");
scanf ("\n学生名字是%s", p[i].name);
printf ("\n");
}
return;
}
void shuchu (struct sss * p, int len)
{
int i;
for (i =0; i < len; ++i)
{
printf ("学生%d的姓名是 %s\n",i+1, p[i].name);
printf ("学生%d的年纪是 %d\n",i+1, p[i].age);
printf ("学生%d的成绩是 %f\n",i+1, p[i].fenshu);
}
return;
}
int main (void)
{
int len;
struct sss * p;
printf ("请输入学生的个数\nlen = ");
scanf ("%d", &len);
p = (struct sss *)malloc (len * sizeof (struct sss));
shuru (p,len);
mao (p,len);
shuchu (p,len);
return 0;
}