大神们!请问怎么 input 函数在循环输入第 2 次的时候,就停止了呢?
#include <stdio.h>#include <malloc.h>
struct Student
{
char name[100];
int age;
char sex;
int score;
};
void input(struct Student ** p,int i)
{
int k,j,n,m,r;
struct Student * t;
for(k=0;k<i;k++)
{
printf("请输入第%d个学生信息:\n",k+1);
scanf("%s %d %c %d",&p[k]->name,&p[k]->age,&p[k]->sex,&p[k]->score);
}
for(m=0;m<i;m++)
{
for(n=1;n<=i-1-m;n++)
{
if((p[m]->score)>(p[n]->score))
{
t=p[m];
p[m]=p[n];
p[n]=t;
}
for (r=0;r<i;r++)
printf("%s %d %c %d\n",p[k]->name,p[k]->age,p[k]->sex,p[k]->score);
}
}
}
int main (void)
{
int n;
int k;
printf("请输入学生人数:\n");
scanf("%d",&n);
struct Student st;
struct Student * p;
p=(struct Student*)malloc(n*sizeof(struct Student));
input(&p,n);
return 0;
}