-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
77 lines (68 loc) · 1.73 KB
/
utils.c
File metadata and controls
77 lines (68 loc) · 1.73 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
74
75
76
77
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ctacconi <ctacconi@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 18:57:23 by ctacconi #+# #+# */
/* Updated: 2024/04/25 18:01:20 by ctacconi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int is_digit(char c)
{
if (c >= '0' && c <= '9')
return (1);
return (0);
}
int ft_strlen(const char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
i++;
}
return (i);
}
int ft_strncmp(char *s1, char *s2, int n)
{
int i;
i = 0;
while (i < n)
{
if (s1[i] == '\0' || s2[i] == '\0' || s1[i] != s2[i])
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
i++;
}
return (0);
}
int ft_atoi(char *str)
{
int res;
int sign;
int i;
res = 0;
sign = 1;
i = 0;
if (str[i] == '-')
{
sign = -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
res = res * 10 + str[i] - '0';
i++;
}
return (res * sign);
}
void add_elements(t_element *add_element, t_element *tmp, char **argv, int i)
{
add_element->num = ft_atoi(argv[i]);
while (tmp->next)
tmp = tmp->next;
tmp->next = add_element;
add_element->next = NULL;
}