-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorchecks.c
More file actions
112 lines (102 loc) · 2.38 KB
/
errorchecks.c
File metadata and controls
112 lines (102 loc) · 2.38 KB
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
107
108
109
110
111
112
/* ************************************************************************** */
/* */
/* :::::::: */
/* errorchecks.c :+: :+: */
/* +:+ */
/* By: candace <candace@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/06/08 14:07:19 by candace #+# #+# */
/* Updated: 2022/10/20 14:40:39 by cstaats ######## odam.nl */
/* */
/* ************************************************************************** */
#include "pushswap.h"
void *errorcheck(int argc, char **argv)
{
int n;
n = 1;
while (n != argc)
{
if (ft_isdigitstr(argv[n]) == -1)
{
write(1, "Error\n", 7);
exit(EXIT_FAILURE);
}
n++;
}
return (0);
}
void *errorchecks(int argc, char **argv)
{
int *list;
long n;
long temp;
list = ft_calloc(sizeof(int), argc);
if (list == NULL)
return (NULL);
n = 0;
while (n++ < argc - 1)
{
temp = ft_atoi(argv[n]);
if (temp < INT_MIN || temp > INT_MAX || ft_strlen(argv[n]) > 11)
{
write(1, "Error\n", 7);
exit(EXIT_FAILURE);
}
list[n - 1] = temp;
if (isduplicate(list, n - 1, list[n - 1]) == 1)
{
write(1, "Error\n", 7);
free(list);
exit(EXIT_FAILURE);
}
}
return (list);
}
void whichmethod(int *stacka, int arraylen)
{
if (arraylen <= 3)
method3(stacka, arraylen);
else if (arraylen <= 5)
method5(stacka, arraylen);
else
sort(stacka, arraylen);
if (amisorted(stacka, arraylen) == 1)
exit(EXIT_SUCCESS);
else
exit(EXIT_FAILURE);
}
long ft_atoi(char *str)
{
long res;
long cnt;
long pos;
res = 0;
cnt = 0;
pos = 1;
while (str[cnt] == '\n' || str[cnt] == ' ' || str[cnt] == '\t'
|| str[cnt] == '\v' || str[cnt] == '\f' || str[cnt] == '\r')
cnt++;
if (str[cnt] == '-')
{
pos = -1;
cnt++;
}
else if (str[cnt] == '+')
cnt++;
while (str[cnt] >= '0' && str[cnt] <= '9')
{
res = res * 10 + str[cnt] - '0';
cnt++;
}
return (res * pos);
}
size_t ft_strlen(char const *str)
{
size_t cnt;
cnt = 0;
while (str[cnt] != 0)
{
cnt++;
}
return (cnt);
}