-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewRecords.c
227 lines (187 loc) · 5.16 KB
/
viewRecords.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "viewRecords.h"
#include "startMatch.h"
/***********************************
* MAIN SCREEN FOR VIEWING RECORDS *
************************************/
void viewRecords()
{
int match_counter = 0;
char teama[30] = "", teamb[30] = "";
system("color 03");
printf("\nEnter team A: ");
fflush(stdin);
scanf("%s", teama);
printf("Enter team B: ");
fflush(stdin);
scanf("%s", teamb);
match_counter = printList(teama, teamb, &match_counter);
if (match_counter == 0)
{
noMatch();
}
else
{
matchesFound();
}
}
/***********************************
* MATCHES PLAYED BETWEEN THE TEAMS *
************************************/
int printList(char *teama, char *teamb, int *match_counter)
{
FILE *fp;
FILE *nfp;
date scanDate;
char matchCode[5] = "";
char scanTeama[30] = "", scanTeamb[30] = "";
system("cls");
system("color 03");
fp = fopen("matches", "r");
nfp = fopen("newList", "w");
while (!(feof(fp)))
{
fscanf(fp, "%s %s %s %d/%d/%d", matchCode, scanTeama, scanTeamb, &scanDate.d, &scanDate.m, &scanDate.y);
if (((strcmp(teama, scanTeama) == 0) && (strcmp(teamb, scanTeamb) == 0)) || ((strcmp(teama, scanTeamb) == 0) && (strcmp(teamb, scanTeama) == 0)))
{
(*match_counter)++;
if ((*match_counter) == 1)
{
printf("\n******************************************************************************************\n");
printf("\nMATCH CODE FIRST TEAM SECOND TEAM DATE\n\n");
}
printf("%-10s %-30s %-30s %2d/%2d/%2d\n", matchCode, teama, teamb, scanDate.d, scanDate.m, scanDate.y);
fprintf(nfp, "%-10s %-30s %-30s %2d/%2d/%2d\n", matchCode, teama, teamb, scanDate.d, scanDate.m, scanDate.y);
}
}
if ((*match_counter) != 0)
{
printf("\n******************************************************************************************\n");
}
fclose(nfp);
fclose(fp);
return (*match_counter);
}
/***********************************
* IF NO MATCH HAS BEEN PLAYED *
************************************/
void noMatch()
{
int r;
system("color 03");
printf("No match has been played betweem these teams!!!\n");
printf("\n********************\n Press\n\n1 To enter again\n2 Return to main page\n********************\n\n");
do
{
fflush(stdin);
scanf("%d", &r);
switch (r)
{
case 1:
system("cls");
viewRecords();
break;
case 2:
start();
break;
default:
printf("You have entered wrong number!!!\nEnter again: ");
break;
}
} while (r != 1 && r != 2);
}
/***********************************
* IF MATCHES ARE PLAYED *
************************************/
void matchesFound()
{
FILE *nfp;
date matchDate;
int codeCounter = 0;
char matchCode[5], scanCode[5];
char scanTeama[30], scanTeamb[30];
system("color 03");
nfp = fopen("newList", "r");
printf("\nEnter the match code: ");
fflush(stdin);
scanf("%s", scanCode);
while (!(feof(nfp)))
{
fscanf(nfp, "%s %s %s %d/%d/%d", matchCode, scanTeama, scanTeamb, &matchDate.d, &matchDate.m, &matchDate.y);
if (strcmp(matchCode, scanCode) == 0)
{
fclose(nfp);
codeCounter++;
codeFound(matchCode);
break;
}
}
if (codeCounter == 0)
{
fclose(nfp);
noCode();
}
}
/***********************************
* CORRECT CODE IS ENTERED *
************************************/
void codeFound(char *matchCode)
{
int r;
char c;
FILE *mfp;
system("cls");
system("color 03");
mfp = fopen(matchCode, "r");
while (!(feof(mfp)))
{
c = getc(mfp);
putc(c, stdout);
}
fclose(mfp);
printf("\n\n********************\n Press\n\n1 To view another match\n2 Return to main page\n********************\n\n");
do
{
fflush(stdin);
scanf("%d", &r);
switch (r)
{
case 1:
system("cls");
viewRecords();
break;
case 2:
start();
break;
default:
printf("You have entered wrong number!!!\nEnter again: ");
break;
}
} while (r != 1 && r != 2);
}
/***********************************
* WRONG CODE IS ENTERED *
************************************/
void noCode()
{
int r;
system("color 03");
printf("You have entered wrong match code!!!\n");
printf("\n********************\n Press\n\n1 To enter again\n2 Return to main page\n********************\n\n");
do
{
fflush(stdin);
scanf("%d", &r);
switch (r)
{
case 1:
matchesFound();
break;
case 2:
start();
break;
default:
printf("You have entered wrong number!!!\nEnter again:");
break;
}
} while (r != 1 && r != 2);
}