问答题
给定程序MODI1.C中函数fun的功能是:对N名学生的学习成绩,按从高到低的顺序找出前m(m≤10)名学生来,并将这些学生数据存放在一个动态分配的连续存储区中,此存储区的首地址作为函数值返回。 请改正函数fun中指定部位的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #include<stdlib.h>3 #include<string.h>4 #define N 105 typedef struct ss6 { char num[10];7 int s;8 } STU;9 STU *fun(STU a[],int m)10 { STU b[N],*t;11 int i,j,k;12 /**********found**********/13 t=(STU *)calloc(sizeof(STU),m)14 for(i=0;i<N;i++)b[i]=a[i];15 for(k=0;k<m;k++)16 { for(i=j=0;i<N;i++)17 if(b[i].s>b[j].s) j=i ;18 /**********found**********/19 t(k)=b(j);20 b[j].s=0;21 }22 return t;23 }24 outresult(STU a[],FILE *pf)25 { int i;26 for(i=0;i<N;i++)27 fprintf(pf,''No=%s Mark=%d\n'',a[i].num,a[i].s);28 fprintf(pf,''\n\n'');29 }30 main()31 { STU a[N]={{''A01'',81},{''A02'',89},{''A03'',66},{''A04'',87},{''A05'',77},{''A06'',90},{''A07'',79},{''A08'',61},{''A09'',80},{''A10'',71}};32 STU *pOrder;33 int i,m;34 printf(''*****The Original data*****\n'');35 outresult(a,stdout);36 printf(''\nGive the number of the students who have better score:'');37 scanf(''%d'',&m);38 while(m>10)39 { printf(''\nGive the number of the students who have better score:'');40 scanf(''%d'',&m);41 }42 porder=fun(a,m);43 printf(''***** THE RESULT ***** \n'');44 printf(''The top:\n'');45 for(i=0;i<m;i++)46 printf(''%s%d\n'',pOrder[i].num,pOrder[i].s);47 free(pOrder);48 }