aboutsummaryrefslogtreecommitdiff
path: root/rush02/ex00/error.c
blob: 27dba414a7bafdad70a54a38507074844ed73cdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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);
}