【求助函数问题】请大神们帮看看这个程序问题出在哪里
目的:(用于对各个学生的分数从小到大排列)键盘输入学生的个数 n,通过3个函数分别对n个学生的成绩进行输入,排列,输出。下面是程序代码,请各位看看问题出在哪里。
# include <stdio.h>
# include <malloc.h>
struct Student
{
int age;
float score;
char name[100];
};
//输入函数;
void Input(void)
{
int i, len;
struct Student * pArr;
//char name[100];
//float score;
pArr = (struct Student *)malloc(len * sizeof (struct Student));
for(i=0; i<len; i++)
{
printf("请输入第%d个学生的信息:\n", i);
printf("age=");
scanf("%d", &pArr[i].age);
printf("score=");
scanf("%f", &pArr[i].score);
printf("name=");
scanf("%s", pArr[i].name);
}
}
//输出函数
void Output()
{
int i, len;
struct Student * pArr;
//char name[100];
//float score;
pArr = (struct Student *)malloc(len * sizeof (struct Student));
for(i=0; i<len; i++)
{
printf("第%d个学生的信息是:\n", i);
printf("age = %d", pArr[i].age);
printf("score = %f", pArr[i].score);
printf("name = %s", pArr[i].name);
}
}
void change()
{
int i, j, len, age;
struct Student * pArr;
struct Student t;
char name[100];
float score;
for(i=0; i<len-1; i++)
{
for(j=0; j<len-1-i; j++)
{
if(pArr[j].score>pArr[j+1].score)
{
t = pArr[j];
pArr[j] = pArr[j+1];
pArr[j+1] = t;
}
}
}
}
int main(void)
{
int i, len;
struct Student * pArr;
pArr = (struct Student *)malloc(len * sizeof (struct Student));
printf("请输入学生的个数:\n");
printf("len = ");
scanf("%d", &len);
void Input(void);
void change();
void Output();
return 0;
}