-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_and_error.c
56 lines (50 loc) · 1.42 KB
/
check_and_error.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_and_error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mohkhald <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/01 22:19:54 by mohkhald #+# #+# */
/* Updated: 2025/04/05 03:46:38 by mohkhald ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_print_error(t_stack **a)
{
write(2, "Error\n", 6);
ft_free_list(a);
exit(1);
}
int ft_duplicate(t_stack *stack, int n)
{
t_stack *tmp;
tmp = stack;
while (tmp)
{
if (tmp->value == n)
return (1);
tmp = tmp->next;
}
return (0);
}
int ft_check_input(char *s)
{
int i;
i = 0;
if (!s || !*s)
return (1);
if ((s[i] == '+' || s[i] == '-') && !s[i + 1])
return (1);
if (s[i] == '+' || s[i] == '-')
i++;
if (!s[i])
return (1);
while (s[i])
{
if (!ft_isdigit(s[i]))
return (1);
i++;
}
return (0);
}