编写了这个程序,它应该能够打印出 txt 文件中的所有行,但它只打印一个,现在已经看了 1 个小时,我找不到错误,任何帮助都会得到帮助!:)
1 16.07.2011 吉隆坡。17.00 OB - FCN 2 - 0 6.965
1 17.07.2011 kl。14.00 FCM - SIF 1 - 2 5.370
1 17.07.2011 kl。16.00 ACH - HBK 3 - 0 2.227
1 17.07.2011 kl。16.00 SDR - FCK 0 - 2 4.992
前 4 行。
#include <stdio.h>
#include <stdlib.h>
#define MAX_LINE_LGT 200
#define NAME_MAX 200
#define TEAM_MAX 200
struct team{
char name[NAME_MAX];
int five_or_more_goals;
};
typedef struct team team;
void read_data_1(const char *file_name, team teams[]){
FILE *ifp;
char team1[NAME_MAX];
char team2[NAME_MAX];
int goal1, goal2;
int dag, month, year;
double clock;
int attendance;
int round;
team local_match;
ifp = fopen(file_name, "r");
while (fscanf(ifp, "%d %d.%d.%d kl. %lf %4s - %4s %d - %d %d\n", &round, &dag, &month, &year, &clock, team1, team2, &goal1, &goal2, &attendance) == 10){
printf("runde %d den %d %d %d klokken %.2lf, mellem %s og %s endte %d - %d %d så kampen\n", round, dag, month, year, clock, team1, team2, goal1, goal2, attendance);
}
fclose(ifp);
}
int main(void) {
team all_matches_teams[TEAM_MAX];
read_data_1("superliga-2011-2012", all_matches_teams);
return 0;
}