diff --git a/try_mul.c b/try_mul.c new file mode 100644 index 0000000000000000000000000000000000000000..0885a385ffdf747df7febea173b33396c6e926da --- /dev/null +++ b/try_mul.c @@ -0,0 +1,35 @@ +#include <stdio.h> +#include "try.h" + +static ctx_t ctx; + +static int mul(int depth) +{ + int i; + + switch (scanf("%d", &i)) + { + case EOF: + return 1; /* neutral element */ + case 0: + return mul(depth + 1); /* erroneous read */ + case 1: + if (i) + return i * mul(depth + 1); + else + throw(&ctx, 0); + } + return 0; +} + +int main() +{ + int product; + + printf("A list of int, please\n"); + + product = try(&ctx, mul, 0); + printf("product = %d\n", product); + + return 0; +}