-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.c
79 lines (72 loc) · 1.87 KB
/
init.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ltombell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 11:33:31 by ltombell #+# #+# */
/* Updated: 2022/12/12 11:20:43 by ltombell ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static int ft_check_for_doubles(t_lista *list, int nb)
{
t_lista *tmp;
tmp = list;
while (tmp)
{
if (tmp->nb == nb)
return (1);
tmp = tmp->next;
}
return (0);
}
void ft_populate_list(t_lista **lst, int argc, char **argv)
{
int i;
long tmp;
i = 1;
while (i < argc)
{
tmp = ft_atoi(argv[i]);
if (tmp < -2147483648 || tmp > 2147483647)
{
ft_free_list(*lst);
write(2, "Error\nargument outside int range\n", 34);
exit(-1);
}
if (ft_check_for_doubles(*lst, tmp) == 1)
{
ft_free_list(*lst);
write(2, "Error\ndouble number\n", 21);
exit(-1);
}
ft_add_element(lst, tmp);
i++;
}
}
int ft_checkinput_nbrs(int argc, char **argv)
{
int i;
int b;
i = 0;
b = 1;
while (b < argc)
{
if (argv[b][0] == '\0')
return (1);
if ((argv[b][i] == '-' || argv[b][i] == '+')
&& ft_is_number(argv[b][i + 1]) == 1)
i++;
while (argv[b][i])
{
if (ft_is_number(argv[b][i]) == 0)
return (1);
i++;
}
i = 0;
b++;
}
return (0);
}