-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_utils.c
More file actions
73 lines (66 loc) · 1.74 KB
/
main_utils.c
File metadata and controls
73 lines (66 loc) · 1.74 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
72
73
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aylaaouf <aylaaouf@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/24 13:23:15 by aylaaouf #+# #+# */
/* Updated: 2025/02/01 16:25:26 by aylaaouf ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include "utils/utils.h"
void free_spliting(char **string)
{
int i;
i = 0;
while (string[i])
{
free(string[i]);
i++;
}
free(string);
}
void single_input(t_stack_node **stack_a, char *numbers)
{
int value;
char **string;
char **tmp;
string = ft_split(numbers, ' ');
tmp = string;
while (*string)
{
value = ft_atoi(*string);
push(stack_a, value);
string++;
}
free_spliting(tmp);
}
void into_stack(int ac, char **input, t_stack_node **stack_a)
{
int i;
char *numbers;
char *tmp;
char *new_numbers;
i = 1;
numbers = ft_strdup("");
if (!numbers)
return ;
while (i < ac)
{
tmp = ft_strjoin(numbers, " ");
new_numbers = ft_strjoin(tmp, input[i]);
free(tmp);
if (!new_numbers)
{
free(numbers);
return ;
}
free(numbers);
numbers = new_numbers;
i++;
}
single_input(stack_a, numbers);
free(numbers);
}