diff options
Diffstat (limited to 'rush02/ex00/error.c')
| -rw-r--r-- | rush02/ex00/error.c | 62 |
1 files changed, 62 insertions, 0 deletions
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 <yiacono@student.s19.be> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} |
