process_high_score(char *name, int score, int month, int day, int year)
{
int fd;
char hsstring[100];
char s[100];
sprintf(hsstring, "%10d %-10s %02d/%02d/%04d\n", score, name,
month, day, year);
/* Note that this string will have exactly 34 characters, including the
null character */
fd = request_connection("games.cs.utk.edu", 8000);
if (fd >= 0) {
write(fd, hsstring, 34);
while (1) {
j = read(fd, s, 100);
if (j > 0) {
write(1, s, j);
} else {
close(fd);
return;
}
}
}
}
What this does is create a high score string, and send it to a high
score server. The server receives the high score, and then sends
back a big string which is the top 500 scores. The game program prints
out this string.
Hint: if process_high_score("Jim", 100000, 12, 13, 1997) is called, the string:
" 100000 Jim 12/13/1997\n"will be sent to the server. Note that if you call atoi() on that string, it will return 100000.