-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_utils.c
More file actions
120 lines (110 loc) · 2.42 KB
/
Copy patherror_utils.c
File metadata and controls
120 lines (110 loc) · 2.42 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: admansar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/24 13:33:30 by admansar #+# #+# */
/* Updated: 2023/03/29 22:00:52 by admansar ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
// to check if the input is a number (returns 0 in this case)
int check_if_number(char *c, int i, int n, int j)
{
if (j == INT_MAX || j == INT_MIN)
return (1);
else if (j > 0)
{
if (c[0] == '+')
n = yup(j, ++n, ++i, c);
else
n = yup(j, n, i, c);
}
else if (j < 0)
{
n = yup(-j, ++n, ++i, c);
}
else if (j == 0)
{
if (c[i] == '+' || c[i] == '-')
i++;
while (c[i] == '0')
i++;
return (((int)ft_strlen(c) == i));
}
return (((int)ft_strlen(c) == n));
}
char *hla9(char *c)
{
int i;
char *re;
re = ft_calloc(sizeof(char), ft_strlen(c));
i = 0;
while (c[i + 1])
{
re[i] = c[i + 1];
i++;
}
re[i] = '\0';
ft_strlcpy(c, re, ft_strlen(re) + 1);
free(re);
return (c);
}
char *ft_str_join(char *s1, char *s2)
{
char *re;
re = ft_strjoin(s1, s2);
free(s2);
return (re);
}
char *n9i(char *c)
{
int i;
char *tmp;
int negative;
i = 0;
negative = 0;
if (c[i] == '+' && ft_strlen(c) > 1)
hla9(c);
else if (c[i] == '-' && ft_strlen(c) > 1)
{
hla9(c);
negative = 1;
}
while (c[i] == '0' && c[i + 1])
hla9(c);
if (negative == 1 && ft_strncmp(c, "0", 2))
{
tmp = ft_strjoin("-", c);
ft_strlcpy(c, tmp, ft_strlen(tmp) + 1);
free(tmp);
}
return (c);
}
// to check that you have not repeat a world
int detective(char **c)
{
int i;
int j;
char *holder;
i = 0;
j = 0;
while (c[i])
{
holder = n9i(c[i]);
ft_strlcpy(c[i], holder, ft_strlen(holder) + 1);
j = i + 1;
while (c[j])
{
if (ft_atoi(c[i]) == ft_atoi(c[j]))
{
return (1);
}
j++;
}
i++;
}
return (0);
}