-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbonus_check_args.c
85 lines (78 loc) · 1.73 KB
/
bonus_check_args.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bonus_check_args.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alouzizi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/17 21:15:46 by alouzizi #+# #+# */
/* Updated: 2022/03/17 21:15:59 by alouzizi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap_bonus.h"
int check1(char **s)
{
int i;
int j;
i = 0;
while (s[i])
{
j = i + 1;
if (ft_atoi(s[i]) > INT_MAX || ft_atoi(s[i]) < INT_MIN)
return (1);
while (s[j])
{
if (ft_atoi(s[i]) == ft_atoi(s[j]))
return (1);
j++;
}
i++;
}
return (0);
}
int check2(char **s)
{
int i;
int j;
i = 0;
while (s[i])
{
j = 0;
while (s[i][j])
{
if (s[i][j] == '+' || s[i][j] == '-')
j++;
if (s[i][j] == '\0')
return (1);
while (s[i][j])
{
if (!ft_isdigit(s[i][j]))
return (1);
j++;
}
}
i++;
}
return (0);
}
int ckeck_args(char **s, char *str)
{
int i;
int j;
i = 0;
j = 0;
while (str[i++] == ' ')
j++;
if (j == (int)ft_strlen(str))
{
write(2, "Error\n", 6);
exit(1);
}
if (check1(s) == 0 && check2(s) == 0)
return (0);
else
{
write(1, "Error\n", 6);
return (1);
}
}