1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)getword.c 5.3 (Berkeley) 06/01/90"; 10 #endif /* not lint */ 11 12 # include "hangman.h" 13 14 # if pdp11 15 # define RN (((off_t) rand() << 16) | (off_t) rand()) 16 # else 17 # define RN rand() 18 # endif 19 20 /* 21 * getword: 22 * Get a valid word out of the dictionary file 23 */ 24 getword() 25 { 26 register FILE *inf; 27 register char *wp, *gp; 28 29 inf = Dict; 30 for (;;) { 31 fseek(inf, abs(RN % Dict_size), 0); 32 if (fgets(Word, BUFSIZ, inf) == NULL) 33 continue; 34 if (fgets(Word, BUFSIZ, inf) == NULL) 35 continue; 36 Word[strlen(Word) - 1] = '\0'; 37 if (strlen(Word) < MINLEN) 38 continue; 39 for (wp = Word; *wp; wp++) 40 if (!islower(*wp)) 41 goto cont; 42 break; 43 cont: ; 44 } 45 gp = Known; 46 wp = Word; 47 while (*wp) { 48 *gp++ = '-'; 49 wp++; 50 } 51 *gp = '\0'; 52 } 53 54 /* 55 * abs: 56 * Return the absolute value of an integer 57 */ 58 off_t 59 abs(i) 60 off_t i; 61 { 62 if (i < 0) 63 return -(off_t) i; 64 else 65 return (off_t) i; 66 } 67