-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_swap_utils2.c
53 lines (49 loc) · 1.5 KB
/
push_swap_utils2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fraqioui <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/24 19:15:47 by fraqioui #+# #+# */
/* Updated: 2022/12/24 19:15:48 by fraqioui ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_error(void)
{
write(1, "Error\n", 6);
exit(1);
}
static int ft_check(char c)
{
if (c == '\n' || c == '\t' || c == '\r'
|| c == '\v' || c == '\f' || c == ' ')
return (1);
return (0);
}
int ft_atoi(const char *str)
{
int sign;
int res;
int pre;
sign = 1;
res = 0;
if (*str != '\0' && ft_check(*str) == 1)
str++;
if (*str == '+')
str++;
else if (*str == '-')
{
sign = -1;
str++;
}
while (*str >= '0' && *str <= '9')
{
pre = res;
res = (res * 10) + ((*str++) - '0');
}
if ((pre != (res / 10)) || (*str && (!(*str >= '0' && *str <= '9'))))
ft_error();
return (sign * res);
}