-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_check.c
executable file
·89 lines (79 loc) · 1.78 KB
/
ft_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
86
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abadidi < [email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/11 19:57:36 by abadidi #+# #+# */
/* Updated: 2022/02/23 09:42:36 by abadidi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int check1(char *str)
{
int i;
i = 1;
while (str[i])
{
if (!(str[i] >= '0' && str[i] <= '9'))
return (0);
i++;
}
return (1);
}
int check(char *str)
{
int i;
int size;
long long atoi;
i = 0;
while (str[i])
{
if ((str[i] != '-' && str[i] != '+') && ft_isdigit(str[i]) == 0)
return (0);
i++;
}
size = ft_strlen(str);
if (size > 11)
return (0);
atoi = ft_atoi(str);
if (atoi > 2147483647 || atoi < -2147483648)
return (0);
return (1);
}
void gobal_check(int argc, char **argv)
{
int i;
i = 1;
if (argc == 1)
{
exit(0);
}
while (i < argc)
{
if (check(argv[i]) == 0 || check1(argv[i]) == 0)
{
print("Error\n");
exit(1);
}
i++;
}
}
void free_tabs(int *a, int *b)
{
free(a);
free(b);
}
void free_stack(t_stack *s)
{
t_stack *temp;
t_stack *tofree;
temp = s;
while (temp)
{
tofree = temp;
temp = temp->next;
free(tofree);
}
}