-
Notifications
You must be signed in to change notification settings - Fork 0
/
team.c
68 lines (60 loc) · 1.48 KB
/
team.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "team.h"
/*
** Inicializa um time.
** @param name Nome do time
** @return team Time criado
*/
TEAM initializeTeam(char *name) {
TEAM team;
memcpy(team.name, name, strlen(name));
team.name[strlen(name)] = '\0';
team.wins = 0;
team.draws = 0;
team.goals_pro = 0;
team.goals_con = 0;
return team;
}
/*
** Escreve um time no arquivo.
** @param f Arquivo.
** @param team Time
*/
void printTeam(FILE *f, TEAM team) {
fprintf(f, "%s %i %i %i %i\n", team.name, calculatePoints(team), team.wins, calculateGoals(team), team.goals_pro);
}
/*
** Recupera um time pelo nome.
** @param name Nome do time
** @param teams Times
** @return num Numero de Times
*/
TEAM *getTeamByName(char *name, TEAM *teams, int num) {
int i;
for (i = 0; i < num; ++i) {
if (!strcmp(teams[i].name, name)) return &teams[i];
}
return NULL;
}
/*
** Escreve a rodada de um torneio no arquivo.
** @param f Arquivo.
** @param round Numero da rodada.
** @param t Torneio
*/
void printRound(FILE *f, int round, TOURNAMENT t) {
int i;
fprintf( f, "%d\n", round);
for (i = 0; i < t.teamsNum; ++i) { printTeam(f, t.teams[i]); }
}
/*
** Calcula os pontos de um time.
** @param team Time
** @return pontos do time
*/
int calculatePoints (TEAM team) { return team.wins * WIN_POINTS + team.draws; };
/*
** Calcula o saldo de gols de um time.
** @param team Time
** @return saldo de gols do time
*/
int calculateGoals (TEAM team) { return team.goals_pro - team.goals_con; };