-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities_2.c
86 lines (77 loc) · 1.77 KB
/
utilities_2.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
80
81
82
83
84
85
86
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utilities_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: natamazy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/13 15:55:44 by natamazy #+# #+# */
/* Updated: 2024/02/22 17:19:34 by natamazy ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int ft_isdigit(int c)
{
if ((c >= 48 && c <= 57))
return (1);
return (0);
}
int ft_str_isdigit(char *str)
{
int i;
i = 0;
while (str[i])
{
if (ft_isdigit(str[i]) == 0)
return (0);
i++;
}
return (1);
}
int print_error(char *message)
{
ft_putstr(message, 2);
return (1);
}
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
size_t j;
char *str;
if (s == NULL)
return ("");
if (len <= ft_strlen(s))
str = (char *) malloc(sizeof(char) * (len + 1));
else
str = (char *) malloc(sizeof(char) * (ft_strlen(s) + 1));
if (!str)
return (NULL);
i = 0;
j = 0;
while (s[i])
{
if (i >= start && j < len)
{
str[j] = s[i];
j++;
}
i++;
}
str[j] = '\0';
return (str);
}
void ft_lstclear(t_list **lst)
{
t_list *t;
t_list *l;
if (!lst)
return ;
l = *lst;
while (l)
{
t = l->next;
free(l);
l = t;
}
*lst = NULL;
}