所以我有一长串的自行车手,我需要将它排成一个结构数组,所以它就是
种族,名字,姓氏,年龄,团队,国籍,安置和运行时间。
到目前为止,我已设法做到这一点,但当我来到一个有两个名字的人(在这个问题Mads Wurst)时,它会混乱我的整个阵列,无论我尝试它似乎都没有解决它。
名称列表如下所示:
ParisRoubaix“Mickael DELAGE”32 FDJ FRA 43 5:50:48
ParisRoubaix“Iljo KEISSE”35 QST BEL 44 5:50:48
ParisRoubaix“Matthieu LADAGNOUS”33 FDJ FRA 45 5:50:48
ParisRoubaix“Mads Wurtz SCHMIDT”23 KAT DEN 46 5:50:48
ParisRoubaix“Dylan GROENEWEGEN”24 TLJ NED 47 5:50:48
ParisRoubaix“Reto HOLLENSTEIN”32 KAT SUI 48 5:50:48
我的代码看起来像这样:
int printAllRiders(void){
char full_data_array[RACE_DATA_SIZE];
race_results *each_race = malloc(sizeof(race_results)*RACE_DATA_SIZE);
FILE *inputp;
inputp = fopen("cykelloeb-2017.txt", "r");
int i = 0;
if(inputp != NULL)
{
while(i<50/*(temp_var = fgetc(inputp)) !=EOF*/)
{
fscanf(inputp, " %s \"%[-A-z] %[ ABCDEFGHIJKLMNOPQRSTUVWXYZ' ]\" %[0-9] %[A-Z] %[A-Z] %s %s",
each_race[i].race,
each_race[i].name_first,
each_race[i].name_last,
each_race[i].age,
each_race[i].team,
each_race[i].nationality,
each_race[i].placement,
each_race[i].finishing_time);
printf("Race: %s\n, first name: %s\n, last name: %s\n, age: %s\n, team: %s\n, nationality: %s\n, placement: %s\n, time: %s\n",
each_race[i].race,
each_race[i].name_first,
each_race[i].name_last,
each_race[i].age,
each_race[i].team,
each_race[i].nationality,
each_race[i].placement,
each_race[i].finishing_time);
i++;
}
} else {
printf("ERROR: Input file could not be opened");
exit(EXIT_FAILURE);
}
fclose(inputp);
full_data_array[i] = '\0';
}