-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildstack.c
40 lines (38 loc) · 1.28 KB
/
buildstack.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* buildstack.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yst-laur <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 14:06:08 by yst-laur #+# #+# */
/* Updated: 2022/03/09 14:06:12 by yst-laur ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int *buildstack(char *argv[], int *stack, int argc)
{
int i;
int j;
long long res;
i = 0;
j = 0;
while (argv[++i])
{
res = ft_atoi(argv[i]);
if (res < -2147483648 || res > 2147483647)
{
free(stack);
write(2, "Error\n", 6);
exit(1);
}
stack[j++] = res;
}
if (!checkdupe(stack, argc))
{
free(stack);
write(2, "Error\n", 6);
exit(1);
}
return (stack);
}