1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)snscore.c	5.1 (Berkeley) 5/30/85";
   9: #endif not lint
  10: 
  11: #include <stdio.h>
  12: #include <pwd.h>
  13: char *recfile = "/usr/games/lib/snakerawscores";
  14: #define MAXPLAYERS 256
  15: 
  16: struct  passwd  *getpwuid();
  17: char    *malloc();
  18: 
  19: struct  player  {
  20:     short   uids;
  21:     short   scores;
  22:     char    *name;
  23: } players[MAXPLAYERS], temp;
  24: 
  25: main()
  26: {
  27:     char    buf[80], cp;
  28:     short   uid, score;
  29:     FILE    *fd;
  30:     int noplayers;
  31:     int i, j, notsorted;
  32:     short   whoallbest, allbest;
  33:     char    *q;
  34:     struct  passwd  *p;
  35: 
  36:     fd = fopen(recfile, "r");
  37:     if (fd == NULL) {
  38:         perror(recfile);
  39:         exit(1);
  40:     }
  41:     printf("Snake players scores to date\n");
  42:     fread(&whoallbest, sizeof(short), 1, fd);
  43:     fread(&allbest, sizeof(short), 1, fd);
  44:     for (uid=2;;uid++) {
  45:         if(fread(&score, sizeof(short), 1, fd) == 0)
  46:             break;
  47:         if (score > 0) {
  48:             if (noplayers > MAXPLAYERS) {
  49:                 printf("too many players\n");
  50:                 exit(2);
  51:             }
  52:             players[noplayers].uids = uid;
  53:             players[noplayers].scores = score;
  54:             p = getpwuid(uid);
  55:             if (p == NULL)
  56:                 continue;
  57:             q = p -> pw_name;
  58:             players[noplayers].name = malloc(strlen(q)+1);
  59:             strcpy(players[noplayers].name, q);
  60:             noplayers++;
  61:         }
  62:     }
  63: 
  64:     /* bubble sort scores */
  65:     for (notsorted=1; notsorted; ) {
  66:         notsorted = 0;
  67:         for (i=0; i<noplayers-1; i++)
  68:             if (players[i].scores < players[i+1].scores) {
  69:                 temp = players[i];
  70:                 players[i] = players[i+1];
  71:                 players[i+1] = temp;
  72:                 notsorted++;
  73:             }
  74:     }
  75: 
  76:     j = 1;
  77:     for (i=0; i<noplayers; i++) {
  78:         printf("%d:\t$%d\t%s\n", j, players[i].scores, players[i].name);
  79:         if (players[i].scores > players[i+1].scores)
  80:             j = i+2;
  81:     }
  82:     exit(0);
  83: }

Defined functions

main defined in line 25; never used

Defined variables

players defined in line 23; used 14 times
recfile defined in line 13; used 2 times
sccsid defined in line 8; never used
temp defined in line 23; used 2 times

Defined struct's

player defined in line 19; never used

Defined macros

MAXPLAYERS defined in line 14; used 2 times
Last modified: 1985-05-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1288
Valid CSS Valid XHTML 1.0 Strict