summaryrefslogtreecommitdiffstats
path: root/games
diff options
context:
space:
mode:
authorbillf <billf@FreeBSD.org>1999-12-12 06:40:28 +0000
committerbillf <billf@FreeBSD.org>1999-12-12 06:40:28 +0000
commit9c9d5f88d9b204e3a4bd9974961b1e1cfff5b952 (patch)
tree40e36dd6b862b6ed310f76389689e494baec1b3c /games
parenta0c828b06418103b489d750e6b91c4223f9410c6 (diff)
downloadFreeBSD-src-9c9d5f88d9b204e3a4bd9974961b1e1cfff5b952.zip
FreeBSD-src-9c9d5f88d9b204e3a4bd9974961b1e1cfff5b952.tar.gz
-Wall fixes.
Diffstat (limited to 'games')
-rw-r--r--games/arithmetic/arithmetic.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/games/arithmetic/arithmetic.c b/games/arithmetic/arithmetic.c
index 86db150..38adab2 100644
--- a/games/arithmetic/arithmetic.c
+++ b/games/arithmetic/arithmetic.c
@@ -82,6 +82,8 @@ static const char rcsid[] =
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
const char keylist[] = "+-x/";
const char defaultkeys[] = "+-";
@@ -92,6 +94,14 @@ int nright, nwrong;
time_t qtime;
#define NQUESTS 20
+static void usage __P((void));
+int getrandom __P((int, int, int));
+void intr __P((int));
+int opnum __P((int));
+void penalise __P((int, int, int));
+int problem __P((void));
+void showstats __P((void));
+
/*
* Select keys from +-x/ to be asked addition, subtraction, multiplication,
* and division problems. More than one key may be given. The default is
@@ -104,10 +114,7 @@ main(argc, argv)
int argc;
char **argv;
{
- extern char *optarg;
- extern int optind;
int ch, cnt;
- void intr();
/* Revoke setgid privileges */
setgid(getgid());
@@ -157,13 +164,15 @@ main(argc, argv)
/* Handle interrupt character. Print score and exit. */
void
-intr()
+intr(sig)
+ int sig;
{
showstats();
exit(0);
}
/* Print score. Original `arithmetic' had a delay after printing it. */
+void
showstats()
{
if (nright + nwrong > 0) {
@@ -184,6 +193,7 @@ showstats()
* answer causes the numbers in the problem to be penalised, so that they are
* more likely to appear in subsequent problems.
*/
+int
problem()
{
char *p;
@@ -191,6 +201,9 @@ problem()
int left, op, right, result;
char line[80];
+ left = 0;
+ right = 0;
+ result = 0;
op = keys[random() % nkeys];
if (op != '/')
right = getrandom(rangemax + 1, op, 1);
@@ -295,6 +308,7 @@ struct penalty {
* operand number `operand' (0 or 1). If we run out of memory, we just
* forget about the penalty (how likely is this, anyway?).
*/
+void
penalise(value, op, operand)
int value, op, operand;
{
@@ -315,6 +329,7 @@ penalise(value, op, operand)
* as a value, or represents a position in the penalty list. If the latter,
* we find the corresponding value and return that, decreasing its penalty.
*/
+int
getrandom(maxval, op, operand)
int maxval, op, operand;
{
@@ -360,6 +375,7 @@ getrandom(maxval, op, operand)
}
/* Return an index for the character op, which is one of [+-x/]. */
+int
opnum(op)
int op;
{
@@ -374,6 +390,7 @@ opnum(op)
}
/* Print usage message and quit. */
+static void
usage()
{
(void)fprintf(stderr, "usage: arithmetic [-o +-x/] [-r range]\n");
OpenPOWER on IntegriCloud