-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_check.c
85 lines (76 loc) · 1.91 KB
/
error_check.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lstorey <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/13 15:32:29 by lstorey #+# #+# */
/* Updated: 2024/03/20 15:56:26 by lstorey ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static int checking_dups(int tmp, char **array)
{
int i;
i = 1;
while (array[i])
{
if (tmp == ft_atol(array[i]))
return (1);
i++;
}
return (0);
}
static int number_checker(char *str)
{
int i;
i = 0;
if (str[0] == '\0')
{
ft_putendl_fd("Error", 2);
exit(0);
}
if (str[i] == '-' || str[i] == '+')
{
i++;
if (!ft_isdigit(str[i]))
return (1);
}
while (str[i])
{
if (ft_isdigit(str[i]) == 0)
return (1);
i++;
}
return (0);
}
static size_t my_strlen(const char *str)
{
size_t i;
i = 0;
if (str[i] == '+' || str[i] == '-')
i++;
while (str[i])
i++;
return (i);
}
void error_check(char **array, int split_flag)
{
int i;
long tmp;
i = 0;
while (array[i])
{
tmp = ft_atol(array[i]);
if (number_checker(array[i]) == 1)
error_exit(array, split_flag);
if (my_strlen(array[i]) > 11)
error_exit(array, split_flag);
if (tmp < MIN_INT || tmp > MAX_INT)
error_exit(array, split_flag);
if (checking_dups(tmp, &array[i]) == 1)
error_exit(array, split_flag);
i++;
}
}