summaryrefslogtreecommitdiff
path: root/11.c
diff options
context:
space:
mode:
Diffstat (limited to '11.c')
-rw-r--r--11.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/11.c b/11.c
index 5f14466..09894d8 100644
--- a/11.c
+++ b/11.c
@@ -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) {