-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_swap_utils.c
54 lines (49 loc) · 1.48 KB
/
push_swap_utils.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mskeleto <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/24 00:36:44 by mskeleto #+# #+# */
/* Updated: 2021/10/07 00:18:17 by mskeleto ### ########.fr */
/* */
/* ************************************************************************** */
#include "ps.h"
int ft_isdigit(int c)
{
if ((c > 47) && (c < 58))
return (1);
else
return (0);
}
int ft_atoi(const char *str)
{
long int resul;
int positive;
positive = 1;
resul = 0;
while (*str == ' ' || (*str >= 9 && *str <= 13))
str++;
if (*str == '+')
str++;
else if (*str == '-')
{
positive = -1;
str++;
}
while (ft_isdigit(*str))
{
resul = resul * 10 + (*str - 48);
if ((resul > 2147483648) && (positive == -1))
return (-1);
if ((resul > 2147483647) && (positive == 1))
return (-1);
str++;
}
return (positive * resul);
}
void ft_error(void)
{
write(1, "Error\n", 6);
}