-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
71 lines (63 loc) · 1.68 KB
/
utils.c
File metadata and controls
71 lines (63 loc) · 1.68 KB
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
63
64
65
66
67
68
69
70
71
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: earnaud <earnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/31 16:10:59 by earnaud #+# #+# */
/* Updated: 2021/07/16 16:14:25 by earnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
return (1);
return (0);
}
void get_sorted(long *stack, long *result)
{
int i;
i = 1;
result[0] = find_next(stack, 0);
while (i <= stack_nb(stack))
{
result[i] = find_next(stack, result[i - 1]);
i++;
}
}
int other_than_num(const char *str)
{
while (*str)
{
if (!ft_isdigit(*str))
return (1);
str++;
}
return (0);
}
long ft_atoi(const char *str)
{
int i;
long nbr;
int neg;
i = 0;
while ((str[i] >= 9 && str[i] <= 13) || str[i] == ' ')
i++;
neg = (str[i] == '-') * -2 + 1;
if (str[i] == '+' || str[i] == '-')
i++;
nbr = 0;
while (str[i] >= '0' && str[i] <= '9')
{
nbr = nbr * 10 + str[i] - '0';
i++;
}
return (nbr * neg);
}
int error(int ret)
{
write(STDOUT_FILENO, "Error\n", 6);
return (ret);
}