Skip to content
Snippets Groups Projects
Commit 04319237 authored by Thierno souleymane Bah's avatar Thierno souleymane Bah
Browse files

feat(try() and throw() tested by doing )

parent 3ae355cd
No related branches found
No related tags found
No related merge requests found
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment