#include "bugs.h" char ScoreString[10]; struct ScoreStruct { char Name[10]; int Score; } High[10]; CheckHiScore( ThisScore ) int ThisScore; { int oldmask,fd,i,j; int writeflag; writeflag = FALSE; oldmask = umask(0); if ((fd=open(SCORE_FILE,O_CREAT|O_RDONLY,0666)) != -1) { read(fd,High,sizeof(High)); close(fd); } else { mvaddstr(22,0,"Couldn't open high score file for read."); } umask(oldmask); for (i=0; i<10; i++) /* place this guy */ if (High[i].Score <= ThisScore) break; if (i < 10 ) /* insert this score */ { writeflag = TRUE; for (j=9; j>i; j--) /* move down others */ if (High[j-1].Score) { High[j].Score = High[j-1].Score; strncpy(High[j].Name,High[j-1].Name,10); } cuserid((char *) High[i].Name); High[i].Score = ThisScore; } if ( writeflag ) { if ((fd=open(SCORE_FILE,O_RDWR)) != -1) { write(fd,High,sizeof(High)); close(fd); } else mvaddstr(22,0,"Couldn't open high score file to write."); } } DisplayHiScores() { int i; mvaddstr( 7, 26, " NAME SCORE\n"); mvaddstr( 8, 26, " ---- -----\n"); for( i=0; i<10; i++ ){ wgoto( wn, 9 + i, 25 ); printf( "%2d. %s %d\n", i+1, (char *)High[i].Name, High[i].Score); } }