Minor fixes
[unix-history] / usr / src / games / hangman / getword.c
CommitLineData
ef609d98 1/*
b8c620d6 2 * Copyright (c) 1983 Regents of the University of California.
ef609d98
KB
3 * All rights reserved.
4 *
7c5ab767 5 * %sccs.include.redist.c%
ef609d98
KB
6 */
7
8#ifndef lint
7c5ab767 9static char sccsid[] = "@(#)getword.c 5.3 (Berkeley) %G%";
ef609d98
KB
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 */
24getword()
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;
43cont: ;
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 */
58off_t
59abs(i)
60off_t i;
61{
62 if (i < 0)
63 return -(off_t) i;
64 else
65 return (off_t) i;
66}