-
Notifications
You must be signed in to change notification settings - Fork 0
/
UNLOAD.C
148 lines (122 loc) · 4.06 KB
/
UNLOAD.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
#include "golf.h"
/*
**************************************************************************
unload.c Brett A. Morrison
Contains the routines for writing the contents of the player and course
arrays to disk.
**************************************************************************
*/
/*
--------------------------------------------------------------------------
UnloadCourses
Unload one course at a time until end of the array is reached.
Inputs:
hFile - the handle to the file to be written to
*courses - the course array
Outputs:
None
--------------------------------------------------------------------------
*/
void UnloadCourses(HANDLE hFile, course_array *courses)
{
int i;
for (i=0; i<=(*courses).course_numb; i++)
{
unload_string(hFile, (*courses).course[i].c_name);
unload_string(hFile, (*courses).course[i].c_street);
unload_string(hFile, (*courses).course[i].c_city);
unload_string(hFile, (*courses).course[i].c_state);
unload_string(hFile, (*courses).course[i].c_zip);
unload_string(hFile, (*courses).course[i].c_phone);
unload_string(hFile, (*courses).course[i].c_rating);
unload_holes (hFile, (*courses).course[i].hole_par);
unload_holes (hFile, (*courses).course[i].hole_handicap);
} /* for */
} /* UnloadCourses */
/*
--------------------------------------------------------------------------
UnloadPlayers
Unload one player at a time until end of the array is reached.
Inputs:
hFile - the handle to the file to be written to
*courses - the player array
Outputs:
None
--------------------------------------------------------------------------
*/
void UnloadPlayers(HANDLE hFile, player_array *players)
{ /* UnloadPlayers */
int i;
for (i=0; i<=(*players).player_numb; i++)
{
unload_string(hFile, (*players).player[i].p_first);
unload_string(hFile, (*players).player[i].p_last);
unload_string(hFile, (*players).player[i].p_street);
unload_string(hFile, (*players).player[i].p_city);
unload_string(hFile, (*players).player[i].p_state);
unload_string(hFile, (*players).player[i].p_zip);
unload_string(hFile, (*players).player[i].p_phone);
unload_history(hFile, &(*players).player[i].p_scores);
} /* for */
} /* UnloadPlayers */
/*
--------------------------------------------------------------------------
unload_string
Write a string to the hFile by calling _lwrite.
Inputs:
hFile - the handle to the file to be written to
string - the string to be written
Outputs:
None
--------------------------------------------------------------------------
*/
void unload_string(HANDLE hFile, char string[])
{ /* unload_string */
_lwrite(hFile, string, lstrlen((LPSTR)string));
_lwrite(hFile, "\r\n", 2); /* terminate the string */
} /* unload_string */
/*
--------------------------------------------------------------------------
unload_holes
Unload the array of scores by calling unload_string
Inputs:
hFile - the handle to the file to be written to
score - the array of scores
Outputs:
None
--------------------------------------------------------------------------
*/
void unload_holes(HANDLE hFile, score_array score)
{
int i;
char temp[SCORE_LENGTH+1];
for (i=1; i<=NUM_HOLES; i++)
{
itoa((short)score[i], temp, 10);
unload_string(hFile, temp);
} /* for */
} /* unload_holes */
/*
--------------------------------------------------------------------------
unload_history
Unload the history of each player by calling unload_string and unload_holes
Inputs:
hFile - the handle to the file to be written to
*p_scores - array containing all of the player's scores
Outputs:
None
--------------------------------------------------------------------------
*/
void unload_history(HANDLE hFile, history_array *p_scores)
{
int i;
char temp[DATE_LENGTH+1];
for (i=0; i<=(*p_scores).round_numb; i++)
{
ltoa((*p_scores).history[i].date, temp, 10);
unload_string(hFile, temp);
unload_string(hFile, (*p_scores).history[i].course_name);
unload_holes(hFile, (*p_scores).history[i].score);
} /* for */
unload_string(hFile, "~");
} /* unload_history */