c语言程序设计题(结构体)

1.学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组S中,请编写函数fun,它的功能是函数返回指定学号的学生数据,指定的学号在主函数中输入。若没找到指定学号,在结构体变量中给学号置空串,给成绩置-1,作为函数值返回。(用于字符串比较的函数是stamp,strcmp(a,b)当a和b字符串相等时返回值为0)。注意:部分源程序存在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。给定源程序如下。#include<stdio.h>
#include<string.h>
#define N 16
typedef struct{char num[10];int s;}STREC;
STREC fun(STRECa,charb)
{
}
main(){STREC s[N]={{"GA005",85},{"GA003",76},{"GB002",69},{"GC004",85},{"GD001",91},{"GE007",72},{"GF008",64},{"GH006",87},{"GM015",85},{"GN013",91},{"GK012",64},{"GL014",91},{"GZ011",77},{"GV017",64},{"GA018",64},{"GA016",72}};
STREC h;
char m[10];
int i;
FILE*out;
printf("The originaldata:\n");
for(i=0;i<N;i++){if(i%4==0)printf("\n");
printf("%s%3d",s[i].num,s[i].s);}
printf("\n\nEnter thenumber:");
gets(m);h=fun(s,m);
printf("The data:");
printf("\n%s%4d\n",h.num,h.s);
printf("\n");
out=fopen("out.dat","w");
h=fun(s,"GA013");
fprintf(out,"%s%4dn",h.num,h.s);
fclose(out);}

img


#include <stdio.h> 
#define N 16 
typedef struct 
{     char num[10]; 
    int s; 
} STREC; 
/*************fun函数***************/
int fun( STREC *a,STREC *b,int l, int h ) 
{     
    int i,j=0;
        for(i=0;i<N;i++)
                if(a[i].s<=h&&a[i].s>=l)
                    b[j++]=a[i];
        return j;
} 
/*************fun函数***************/
void main() 
{     STREC s[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},{"GA001",96}, {"GA007",72},{"GA008",64},{"GA006",87},{"GA015",85},{"GA013",94},{"GA012",64}, {"GA014",91},{"GA011",90}, {"GA017",64},{"GA018",64},{"GA016",72}}; 
    STREC h[N],tt;
    int i,j,n,low,heigh,t; 
    printf("Enter 2 integer number low & heigh : "); 
    scanf("%d%d", &low,&heigh); 
    if ( heigh< low ){ t=heigh;heigh=low;low=t; } 
    n=fun( s,h,low,heigh ); 
    printf("The student's data between %d--%d :\n",low,heigh); 
    for(i=0;i<n; i++) 
        printf("%s %4d\n",h[i].num,h[i].s); 
    printf("\n"); 
}