-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project6-main.c
230 lines (209 loc) · 8.51 KB
/
Project6-main.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
228
229
230
/// Project 6 - COP2220 - Domenic Mangani 11/28/14 - main.c
/// stadium name | capacity | expCap | city | state (full) | turf | roof | team | opened
#include "menuOne.h"
#include "menuTwo.h"
int main ( void )
{
FILE *fp, *modified;
stadium_t stadiums[MAX_ELEMENTS];
int count, fileCount, index, input, mainLoop = 0, menuChoice, valid = 0;
char line[LEN_LINE], namesLow[MAX_ELEMENTS][LEN_NAME] = {{ 0 }},
*startPtr, *endPtr, response[LEN_NAME] = { 0 }, tempState[3];
fp = fopen ( "NFLStadiums2.txt", "r" );
if ( NULL == fp )
printf ( "Unable to open file." );
else
{
index = 0;
while ( fgets( line, sizeof(line), fp ) && index < MAX_ELEMENTS )
{
startPtr = strchr ( line, '\n' );
if ( startPtr )
{
startPtr = '\0';
}
startPtr = line;
endPtr = strchr( startPtr, '|' );
strncpy ( stadiums[index].name, startPtr, endPtr - startPtr );
// scan error somewhere between here -
startPtr = endPtr + 1;
endPtr = strchr( startPtr, '|' );
stadiums[index].capacity = atoi ( startPtr );
startPtr = endPtr + 1;
endPtr = strchr( startPtr, '|' );
stadiums[index].expCapacity = atoi ( startPtr );
/// ask how to handle the additional pipe in |St| Louis| (NFLStadium.txt line 5)
startPtr = endPtr + 1;
endPtr = strchr( startPtr, '|' );
strncpy ( stadiums[index].city, startPtr, endPtr - startPtr );
// and here -
startPtr = endPtr + 1;
endPtr = strchr( startPtr, '|' );
strncpy ( stadiums[index].stateFull, startPtr, endPtr - startPtr );
startPtr = endPtr + 1;
endPtr = strchr( startPtr, '|' );
strncpy ( stadiums[index].turf, startPtr, endPtr - startPtr );
startPtr = endPtr + 1;
endPtr = strchr( startPtr, '|' );
strncpy ( stadiums[index].roof, startPtr, endPtr - startPtr );
startPtr = endPtr + 1;
endPtr = strchr( startPtr, '|' );
strncpy ( stadiums[index].team, startPtr, endPtr - startPtr );
startPtr = endPtr + 1;
endPtr = strchr( startPtr, '|' );
stadiums[index].opened = atoi ( startPtr );
startPtr = endPtr + 1;
endPtr = strchr( startPtr, '\0' );
strcpy ( stadiums[index].state, startPtr);
index++;
}
fclose ( fp );
fileCount = index;
}
// copy stadium names into array to format for search
for ( index = 0; index < fileCount; index++ )
{
strcpy( namesLow[index], stadiums[index].name );
lowStr( namesLow[index] );
}
printf ( "Welcome to Project 6!\n" );
while ( mainLoop == 0 )
{
count = 0, input = 0;
printf ( "\nMain Menu:\n1) View/Sort stadium data\n2) Maintain stadium data\n"
"9) Exit\nPlease select (1, 2, or 9): " );
scanf ( "%i", &input );
if ( input == 1 || input == 2 || input == 9 )
{
if ( input == 1 )
{
menuChoice = printMenuOne();
switch ( menuChoice )
{
case 1 : /// print all stadiums
{
for ( index = 0; index < fileCount; index++ )
{
printOneStadium( stadiums, index );
count++;
if ( count == 10 )
{
printf ( "Pausing data list at count: %i\n", count );
system( "PAUSE" );
}
}
printf ( "\nTotal stadiums printed: %i\n\n", count );
break;
}
case 2 : /// search for stadiums by name
{
fflush( stdin );
printf( "\nEnter stadium name, or part of it: " );
fgets( response, sizeof(response), stdin );
response[strlen(response) - 1] = '\0';
lowStr( response );
printf ( "\nSearching stadiums with string: %s\n", response );
for ( index = 0; index < fileCount; index++ )
{
if ( strstr(namesLow[index], response) != NULL )
{
printOneStadium( stadiums, index );
count++;
}
}
if ( count == 0 )
{
printf ( "\nNo stadium(s) found. Please try again.\n\n" );
}
else
printf ( "\nTotal stadium(s) printed: %i\n", count );
break;
}
case 3 : /// search for stadiums by state
{
printf ( "What state to search for? (Florida = FL): ");
scanf ( "%s", tempState );
upStr(tempState);
printf ( "\nSearching stadiums with string: %s\n", tempState );
while ( valid == 0 )
{
if ( strlen(tempState) == 2 )
valid = 1;
else
printf ( "Invalid! Please try again.\n" );
}
for ( index = 0; index < fileCount; index++ )
{
if ( strncmp(stadiums[index].state, tempState, 2 ) == 0 )
{
printOneStadium( stadiums, index );
count++;
}
}
if ( count == 0 )
printf ( "\nNo stadium(s) found. Please try again.\n" );
else
printf ( "Total stadiums printed: %i\n", count );
break;
}
case 4 : /// print all stadiums over capacity
printOverCapacity ( stadiums, fileCount );
break;
case 5 : /// sort data by stadium name
qsort (stadiums, fileCount, sizeof(stadium_t), compare_name );
for ( index = 0; index < fileCount; index++ )
printOneStadium( stadiums, index );
break;
case 6 : /// sort data by capacity
qsort (stadiums, fileCount, sizeof(stadium_t), compare_capacity );
for ( index = 0; index < fileCount; index++ )
printOneStadium( stadiums, index );
break;
default :
break;
}
}
else if ( input == 2 )
{
menuChoice = printMenuTwo();
switch ( menuChoice )
{
case 1 : /// Edit stadium data
printf ( "\nUnder construction.\n\n" );
break;
case 2 : /// Add new stadium
printf ( "\nUnder construction.\n\n" );
break;
case 3 : /// Delete a stadium
printf ( "\nUnder construction.\n\n" );
break;
case 4 : /// Save modified data
//printf ( "\nUnder construction.\n\n" );
modified = fopen ( "Modified.txt", "w" );
if ( NULL == fp )
printf ( "Unable to open file." );
else
{
//for ( index = 0; index < sizeof(stadiums); index++ )
//{
save( stadiums, modified );
//}
printf ( "\nData file saved.\n" );
}
break;
}
}
else if ( input == 9 )
{
mainLoop = 1;
}
}
else
{
printf ( "Invalid! Please try again.\n\n" );
}
}
printf ( "Program closed by user.\n" );
system ( "PAUSE" );
return 0;
}