新问题:我必须将文件中的数据读入结构数组,并且我的 scanf 函数出现错误。我真的不确定扫描到结构的细节。这是我写的:
#include <stdio.h>
#include <string.h>
#include <math.h>
#define runnum 500
#define charnum 20
typedef struct {
unsigned long bibnum;
char lastname[charnum];
char fistname[charnum];
int grade;
char team[charnum];
char state[charnum];
int time1;
float time2;
} runner_t;
int main(void)
{
int i;
FILE *ifile, *jfile;
ifile = fopen("20121006.boys.txt", "r");
jfile = fopen("20121006.girls.txt", "r");
runner_t runarray[runnum];
i = 0;
while (i < runnum)
{
scanf(ifile, "%ul", &runarray[i].bibnum);
scanf(ifile, "%s", &runarray[i].lastname);
scanf(ifile, "%s", &runarray[i].firstname);
scanf(ifile, "%d", &runarray[i].grade);
scanf(ifile, "%s", &runarray[i].team);
scanf(ifile, "%s", &runarray[i].state);
scanf(ifile, "%d", &runarray[i].time1);
scanf(ifile, "%f", &runarray[i].time2);
printf("%d %s %s %d %s %s %d:%f", runarray[i].bibnum, runarray[i].lastname, runarray[i].firstname, runarray[i].grade, runarray[i].team, runarray[i].state, runarray[i].time1, runarray[i].time2);
i++;
}