-
Notifications
You must be signed in to change notification settings - Fork 1
/
verify_errors.c
93 lines (84 loc) · 2.08 KB
/
verify_errors.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
87
88
89
90
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* verify_errors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfranca- <lfranca-@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/08 21:32:20 by lfranca- #+# #+# */
/* Updated: 2022/01/09 18:47:48 by lfranca- ### ########.fr */
/* */
/* ************************************************************************** */
#include "./push_swap.h"
void ft_error(void)
{
ft_putendl_fd("Error", 2);
exit(1);
}
int ft_isnumber(char *c)
{
int j;
int is_number;
j = 0;
is_number = 1;
while (c[j] != '\0')
{
if (c[j] == '-' || c[j] == '+')
j++;
else if (c[j] < 48 || c[j] > 57)
is_number = 0;
j++;
}
return (is_number);
}
void check_isnumber(t_stacka *stack_a)
{
int counter;
int ret;
ret = 1;
counter = -1;
while (++counter < stack_a->len_inputs)
{
ret = ft_isnumber(stack_a->inputs[counter]);
if (ret == 0)
{
free_argvs(stack_a);
ft_error();
}
}
}
static void is_range(long long int value, t_stacka *stack_a)
{
if (value > INT_MAX || value < INT_MIN)
{
free_argvs(stack_a);
ft_error();
}
}
void ft_no_duplicates(t_stacka *stack_a)
{
long long int value;
long long int next_value;
int i;
int j;
i = 0;
value = atoi_long(stack_a->inputs[i]);
is_range(value, stack_a);
while (i < (stack_a->len_inputs - 1))
{
j = i;
while (++j < stack_a->len_inputs)
{
next_value = atoi_long(stack_a->inputs[j]);
if (i == 0)
is_range(next_value, stack_a);
if (value == next_value)
{
free_argvs(stack_a);
ft_error();
}
}
i++;
value = atoi_long(stack_a->inputs[i]);
}
}