-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_stack.c
More file actions
57 lines (51 loc) · 1.62 KB
/
get_stack.c
File metadata and controls
57 lines (51 loc) · 1.62 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_stack.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bhielsch <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/15 12:36:51 by bhielsch #+# #+# */
/* Updated: 2022/12/15 12:36:54 by bhielsch ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void get_stack_twoarg(t_stack *stack, char *str)
{
int i;
if (count_numbers(str) < 2)
error_mess("", stack);
i = -1;
ft_split1(str, ' ', stack);
while (++i < count_numbers(str))
{
stack->stcka[i] = ft_atoi(stack->word[i]);
if (is_equal(stack, stack->word[i], i) == -1)
error_mess("Error\n", stack);
}
}
void get_stack_morearg(t_stack *stack, char *str, int pos)
{
stack->stcka[pos] = ft_atoi(str);
if (is_equal(stack, str, pos) == -1)
error_mess("Error\n", stack);
}
int is_equal(t_stack *stack, char *str, int index)
{
char *str1;
int i;
i = 0;
str1 = ft_itoa(stack->stcka[index]);
while (str1[i])
{
if (str1[i] == str[i])
i++;
else
{
free(str1);
return (-1);
}
}
free(str1);
return (0);
}