version 1.1.1.1, 1993/03/21 09:45:37 |
version 1.1.1.2, 1995/04/22 08:25:54 |
|
|
/* |
/* |
* Copyright (c) 1980 Regents of the University of California. |
* Copyright (c) 1980, 1993 |
* All rights reserved. |
* The Regents of the University of California. All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* modification, are permitted provided that the following conditions |
|
|
*/ |
*/ |
|
|
#ifndef lint |
#ifndef lint |
char copyright[] = |
static char copyright[] = |
"@(#) Copyright (c) 1980 Regents of the University of California.\n\ |
"@(#) Copyright (c) 1980, 1993\n\ |
All rights reserved.\n"; |
The Regents of the University of California. All rights reserved.\n"; |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
#ifndef lint |
#ifndef lint |
static char sccsid[] = "@(#)snscore.c 5.7 (Berkeley) 2/28/91"; |
static char sccsid[] = "@(#)snscore.c 8.1 (Berkeley) 7/19/93"; |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
char *name; |
char *name; |
} players[MAXPLAYERS], temp; |
} players[MAXPLAYERS], temp; |
|
|
|
int |
main() |
main() |
{ |
{ |
char buf[80], cp; |
|
short uid, score; |
short uid, score; |
FILE *fd; |
FILE *fd; |
int noplayers; |
int noplayers; |
|
|
printf("Snake players scores to date\n"); |
printf("Snake players scores to date\n"); |
fread(&whoallbest, sizeof(short), 1, fd); |
fread(&whoallbest, sizeof(short), 1, fd); |
fread(&allbest, sizeof(short), 1, fd); |
fread(&allbest, sizeof(short), 1, fd); |
for (uid=2;;uid++) { |
noplayers = 0; |
|
for (uid = 2; ;uid++) { |
if(fread(&score, sizeof(short), 1, fd) == 0) |
if(fread(&score, sizeof(short), 1, fd) == 0) |
break; |
break; |
if (score > 0) { |
if (score > 0) { |
|
|
if (p == NULL) |
if (p == NULL) |
continue; |
continue; |
q = p -> pw_name; |
q = p -> pw_name; |
players[noplayers].name = malloc(strlen(q)+1); |
players[noplayers].name = malloc(strlen(q) + 1); |
strcpy(players[noplayers].name, q); |
strcpy(players[noplayers].name, q); |
noplayers++; |
noplayers++; |
} |
} |
} |
} |
|
|
/* bubble sort scores */ |
/* bubble sort scores */ |
for (notsorted=1; notsorted; ) { |
for (notsorted = 1; notsorted; ) { |
notsorted = 0; |
notsorted = 0; |
for (i=0; i<noplayers-1; i++) |
for (i = 0; i < noplayers - 1; i++) |
if (players[i].scores < players[i+1].scores) { |
if (players[i].scores < players[i + 1].scores) { |
temp = players[i]; |
temp = players[i]; |
players[i] = players[i+1]; |
players[i] = players[i + 1]; |
players[i+1] = temp; |
players[i + 1] = temp; |
notsorted++; |
notsorted++; |
} |
} |
} |
} |
|
|
j = 1; |
j = 1; |
for (i=0; i<noplayers; i++) { |
for (i = 0; i < noplayers; i++) { |
printf("%d:\t$%d\t%s\n", j, players[i].scores, players[i].name); |
printf("%d:\t$%d\t%s\n", j, players[i].scores, players[i].name); |
if (players[i].scores > players[i+1].scores) |
if (players[i].scores > players[i + 1].scores) |
j = i+2; |
j = i + 2; |
} |
} |
exit(0); |
exit(0); |
} |
} |