Commit | Line | Data |
---|---|---|
ef609d98 | 1 | /* |
891bebb2 KB |
2 | * Copyright (c) 1983, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
ef609d98 | 4 | * |
7c5ab767 | 5 | * %sccs.include.redist.c% |
ef609d98 KB |
6 | */ |
7 | ||
8 | #ifndef lint | |
891bebb2 | 9 | static char sccsid[] = "@(#)getword.c 8.1 (Berkeley) %G%"; |
ef609d98 KB |
10 | #endif /* not lint */ |
11 | ||
f5349cba CT |
12 | #include "hangman.h" |
13 | #include <stdlib.h> | |
ef609d98 KB |
14 | |
15 | /* | |
16 | * getword: | |
17 | * Get a valid word out of the dictionary file | |
18 | */ | |
19 | getword() | |
20 | { | |
21 | register FILE *inf; | |
22 | register char *wp, *gp; | |
f5349cba | 23 | register long pos; |
ef609d98 KB |
24 | |
25 | inf = Dict; | |
26 | for (;;) { | |
f5349cba CT |
27 | pos = (double)rand() / (RAND_MAX + 1.0) * (double)Dict_size; |
28 | fseek(inf, pos, 0); | |
ef609d98 KB |
29 | if (fgets(Word, BUFSIZ, inf) == NULL) |
30 | continue; | |
31 | if (fgets(Word, BUFSIZ, inf) == NULL) | |
32 | continue; | |
33 | Word[strlen(Word) - 1] = '\0'; | |
34 | if (strlen(Word) < MINLEN) | |
35 | continue; | |
36 | for (wp = Word; *wp; wp++) | |
37 | if (!islower(*wp)) | |
38 | goto cont; | |
39 | break; | |
40 | cont: ; | |
41 | } | |
42 | gp = Known; | |
43 | wp = Word; | |
44 | while (*wp) { | |
45 | *gp++ = '-'; | |
46 | wp++; | |
47 | } | |
48 | *gp = '\0'; | |
49 | } |