[BACK]Return to snscore.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / games / snake / snscore

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/games/snake/snscore/snscore.c between version 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 1993/03/21 09:45:37 version 1.1.1.2, 1995/04/22 08:25:54
Line 1 
Line 1 
 /*  /*
  * 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
Line 32 
Line 32 
  */   */
   
 #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>
Line 56  struct player {
Line 56  struct player {
         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;
Line 75  main()
Line 75  main()
         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) {
Line 89  main()
Line 90  main()
                         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);
 }  }

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2

CVSweb <webmaster@jp.NetBSD.org>