Code:
#include <stdio.h>
#define TEAM_LEN 4 //3+end of string 0
void greatest(void);
int main()
{
greatest();
return 0;
}
void greatest(void)
{
int round1, day, month, year, home_goal, away_goal, spectator1, spectator2;
int maxRound, maxHome_goal, maxAway_goal, maxGoals = 0; //etc.
double time1;
char home_team[TEAM_LEN], away_team[TEAM_LEN];
int total_goals;
int i;
FILE *inp;
char row1[100];
inp = fopen("superliga-2012-2013", "r");
if (inp == NULL) {
printf("Error, file not found.\n");
return;
}
fgets(row1, 100, inp); /* get past the first row of info, the header */
printf("%s\n\n",row1);
while (fscanf(inp, "%d %d.%d.%d kl. %lf %s - %s %d - %d %d.%d", &round1, &day, &month, &year, &time1, home_team, away_team, &home_goal, &away_goal, &spectator1, &spectator2) != EOF) {
total_goals = home_goal + away_goal;
//if (total_goals >= 7) {
// printf("%2d %2d.%2d.%4d kl. %.2lf %4s - %4s %2d - %2d %d.%d\n", round1, day, month, year, time1, home_team, away_team, home_goal, away_goal, spectator1, spectator2);
//}
printf("Total goals: %d home_goal: %d away_goal: %d \n",total_goals,home_goal,away_goal);
if (maxGoals <= total_goals) {
maxRound=round1;
maxHome_goal=home_goal;
maxAway_goal=away_goal;
maxGoals = total_goals;
//etc.
}
}
fclose(inp);
printf("\nmaxRound: %d maxHome_goal: %d maxAway_goal: %d maxGoals: %d \n",
maxRound, maxHome_goal, maxAway_goal, maxGoals);
}