diff options
author | Adam Spragg <adam@spra.gg> | 2022-12-11 18:30:43 +0000 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2022-12-11 18:30:43 +0000 |
commit | e9700bcb5457ccc137956558b1f4eb780a748b0d (patch) | |
tree | a9dee20b0b6f62065cf38093c833b91160e6db3d | |
parent | 2517d9765da22386852d75bdfb4f70b5181c0c35 (diff) |
Count the number of inspections as a long
-rw-r--r-- | 11.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -23,7 +23,7 @@ struct monkey { int test_div; int test_true; int test_false; - int inspections; + long inspections; }; @@ -78,7 +78,7 @@ monkey_dump(struct monkey const * m, int n) { unsigned long * item; - fprintf(stderr, "Monkey %d: %d/%d/%d/%d/%d/%d: ", + fprintf(stderr, "Monkey %d: %d/%d/%d/%d/%d/%ld: ", n, m->wo, m->wparam, m->test_div, m->test_true, m->test_false, m->inspections); for (item = m->items; item < m->items + m->nitems; ++item) { fprintf(stderr, "%s%lu", item == m->items ? "" : ", ", *item); @@ -93,7 +93,7 @@ main(int argc, char ** argv) char buf[BUFSIZ]; struct monkey * monkeys = NULL, * m = NULL; int nmonkeys = 0; - int i, j; + long i, j; int calming = 3, rounds = 20; while ((i = getopt(argc, argv, "p:c:r:")) != -1) { @@ -136,7 +136,7 @@ main(int argc, char ** argv) ++nmonkeys; if ((i = atoi(buf + 7)) != nmonkeys - 1) { - fprintf(stderr, "Bad monkey %d/%d!\n", i, nmonkeys); + fprintf(stderr, "Bad monkey %ld/%d!\n", i, nmonkeys); free(monkeys); return -1; } @@ -220,21 +220,21 @@ main(int argc, char ** argv) break; /* shouldn't happen */ case WO_ADD: if (*item > ULONG_MAX - m->wparam) - fprintf(stderr, "%d/%d/%d: Overflow: %lu > %lu - %d\n", + fprintf(stderr, "%ld/%d/%d: Overflow: %lu > %lu - %d\n", i, (int) (monkeys - m), (int) (item - m->items), *item, ULONG_MAX, m->wparam); *item += m->wparam; break; case WO_MUL: if (*item >= ULONG_MAX / m->wparam) - fprintf(stderr, "%d/%d/%d: Overflow: %lu >= %lu / %d\n", + fprintf(stderr, "%ld/%d/%d: Overflow: %lu >= %lu / %d\n", i, (int) (monkeys - m), (int) (item - m->items), *item, ULONG_MAX, m->wparam); *item *= m->wparam; break; case WO_SQR: if (*item >= ULONG_MAX / *item) - fprintf(stderr, "%d/%d/%d: Overflow: %lu >= %lu / %lu\n", + fprintf(stderr, "%ld/%d/%d: Overflow: %lu >= %lu / %lu\n", i, (int) (monkeys - m), (int) (item - m->items), *item, ULONG_MAX, *item); *item *= *item; @@ -268,7 +268,7 @@ main(int argc, char ** argv) j = m->inspections; } } - printf("Monkey business: %d (%d * %d)\n", i * j, i, j); + printf("Monkey business: %ld (%ld * %ld)\n", i * j, i, j); // Done. for (m = monkeys; m < monkeys + nmonkeys; ++m) { |