码迷,mamicode.com
首页 > 其他好文 > 详细

结构体的调用

时间:2016-03-20 16:12:13      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

#include <stdio.h>
#define N 16
typedef struct
{ char num[10];
int s;
} STREC;
int fun( STREC *a, STREC *b )
{
int i;
int j = 0;
int k = 0;
for (i = 0 ;i < 16;i++)
{if(a[i].s < a[i+1].s)//a->s[]是不行的。。
{
j = a[i].s;
}
if(a[i].s >= a[i+1].s)
{
j = a[i+1].s;
};}
printf("%d\n",j);
for (i = 0 ;i < 16;i++)
{
if (a[i].s == j)
{
b[k] = a[i];
k = k+1;
}
}
return k;
}

main()
{ STREC s[N]={{"GA05",85},{"GA03",76},{"GA02",69},{"GA04",85},
{"GA01",91},{"GA07",72},{"GA08",64},{"GA06",87},
{"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},
{"GA011",91},{"GA017",64},{"GA018",64},{"GA016",72}};
STREC h[N];
int i,n;FILE *out ;
n=fun( s,h );
printf("The %d lowest score :\n",n);
for(i=0;i<n; i++)
printf("%s %4d\n",h[i].num,h[i].s);
printf("\n");
out = fopen("out.dat","w") ;
fprintf(out, "%d\n",n);
for(i=0;i<n; i++)
fprintf(out, "%4d\n",h[i].s);
fclose(out);
}

 

结构体的调用

标签:

原文地址:http://www.cnblogs.com/hongmo/p/5297924.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!