-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_checks.c
106 lines (97 loc) · 2.09 KB
/
ft_checks.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
94
95
96
97
98
99
100
101
102
103
104
105
106
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_checks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: iyapar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/29 15:07:16 by iyapar #+# #+# */
/* Updated: 2022/06/30 17:03:37 by iyapar ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
#include <stdio.h>
#include <limits.h>
int *ft_to_arr(char **s, int counter)
{
int *my_arr;
int i;
int k;
i = 1;
k = 0;
my_arr = (int *)malloc(sizeof(int) * counter);
while (s[i])
{
my_arr[k] = ft_atoi(s[i]);
k++;
i++;
}
return (my_arr);
}
int ft_dup_check(char **s, int counter)
{
int i;
int j;
int *my_arr;
i = 0;
my_arr = ft_to_arr(s, counter);
while (i < counter)
{
j = i + 1;
while (j < counter)
{
if (my_arr[i] == my_arr[j])
{
write(1, "Error\n", 6);
return (0);
}
j++;
}
i++;
}
free(my_arr);
return (1);
}
void ft_max_min_check(char *a)
{
if ((ps_atoll(a) <= INT_MAX && ps_atoll(a) >= INT_MIN))
return ;
write(1, "Error\n", 6);
exit (0);
}
int ft_arg_check(char **s)
{
int i;
int j;
i = 1;
while (s[i])
{
ft_max_min_check(s[i]);
j = 0;
while (s[i][j] != '\0')
{
if (s[i][j] == '-' || s[i][j] == '+')
j++;
if (!ft_isdigit(s[i][j]))
{
write(1, "Error\n", 6);
return (0);
}
j++;
}
i++;
}
if (ft_dup_check(s, i - 1) == 0)
return (0);
return (1);
}
int ft_is_sorted(t_struct *stackA)
{
while (stackA->next)
{
if (stackA->value > stackA->next->value)
return (0);
stackA = stackA->next;
}
return (1);
}