求解哪里出的问题,感谢为我解答的人,我将粉粹一切自学编程路上的困难
# include <stdio.h># include <malloc.h>
struct student
{
int age;
float score;
char name[100];
};
int len, i, j;
struct student t; //用于排序中交换两个数字的中间值
void ShuRu (struct student** p)
{
printf ("请输入学生的个数:\n");
printf ("len = ");
scanf ("%d", &len);
* p = (struct student*)malloc (len * sizeof (struct student)); //动态构造一个数组
for (i=0; i<len; ++i)
{
printf ("请输入第%d个学生的信息:\n", i+1);
printf ("age = ");
scanf ("%d", &**(p+i).age);
printf ("score = ");
scanf ("%f", &*p[i].score);
printf ("name = ");
scanf ("%s", *p[i].name);
}
}
void PaiXiu (struct student** r)
{
for (i=1; i<len; ++i)
{
for (j=0; j<len-i; ++j)
{
if (*r[j].score>*r[j+1].score)
{
t = *r[j];
*r[j] = *r[j+1];
*r[j+1] = t;
}
}
}
}
void ShuChu (struct student** w)
{
printf ("\n\n学生的信息是:");
for (i=0; i<len; ++i)
{
printf ("第%d名的学生信息是:", i+1);
printf("age = %d\n", *w[i].age);
printf("name = %s\n", *w[i].name);
printf("score = %f\n", *w[i].score);
}
}
int main (void)
{
struct student* q;
ShuRu (&q); //输入学生的信息
PaiXiu (&q); //根据成绩给学生排序,冒泡法
ShuChu (&q); //对处理完的结果进行输出
return 0;
}