From 0431923754d1ca10702e898e12dfab7a8e627ab6 Mon Sep 17 00:00:00 2001
From: Thierno-Souleymane BAH <thiernosouleymane.bah.etu@univ-lille.fr>
Date: Fri, 15 Jan 2021 07:19:24 +0100
Subject: [PATCH] feat(try() and throw() tested by doing )

---
 try_mul.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 try_mul.c

diff --git a/try_mul.c b/try_mul.c
new file mode 100644
index 0000000..0885a38
--- /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;
+}
-- 
GitLab