From 23ad79e8b41c25bb4992d103d29a17612a52e351 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 21 Jul 2019 15:26:32 +0200 Subject: c10 done, c11 on going, rush02 probably finished, bsq start --- rush02/ex00/error.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 rush02/ex00/error.c (limited to 'rush02/ex00/error.c') diff --git a/rush02/ex00/error.c b/rush02/ex00/error.c new file mode 100644 index 0000000..27dba41 --- /dev/null +++ b/rush02/ex00/error.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* error.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yiacono +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/20 10:55:27 by agassin #+# #+# */ +/* Updated: 2019/07/21 14:17:53 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "include.h" + +/* +** similar to atoi but doesn't allow anything before or after ('-' included) +** return the number or -1 in case of error +*/ + +t_max_nbr strict_atoi(char *str) +{ + t_max_nbr nb; + int i; + + nb = 0; + i = 0; + while (str[i]) + { + if (str[i] < '0' || str[i] > '9') + return (-1); + i++; + } + if (i == 0) + return (-1); + i = 0; + while (str[i]) + { + nb *= 10; + nb += str[i++] - '0'; + } + return (nb); +} + +int print_error_if(int status, t_dict dict) +{ + if (status) + { + ft_putstr("Error\n"); + destroy_dict(dict, -1); + } + return (status); +} + +int print_dict_error_if(int status, t_dict dict) +{ + if (status) + { + ft_putstr("Dict Error\n"); + destroy_dict(dict, -1); + } + return (status); +} -- cgit