-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_checker.c
More file actions
65 lines (55 loc) · 1.63 KB
/
error_checker.c
File metadata and controls
65 lines (55 loc) · 1.63 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error_checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sarfreit <sarfreit@student.42porto.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/29 21:20:44 by sarfreit #+# #+# */
/* Updated: 2026/01/25 22:58:03 by sarfreit ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
/// Only digits and one sign
int is_valid_int_token(char *s)
{
int i;
i = 0;
if (!s || !s[0])
return (0);
if ((s[i] == '-') || s[i] == '+')
i++;
if (!ft_isdigit(s[i]))
return (0);
while (s[i])
{
if (!ft_isdigit(s[i]))
return (0);
i++;
}
return (1);
}
// Check if num is not exceeding the integer limits
int is_in_range_int(char *s)
{
long num;
num = ft_atol(s);
if ((num >= -2147483648L) && (num <= 2147483647L))
return (1);
return (0);
}
// Check for duplicate numbers
int has_duplicate(t_stack *stack, int value)
{
t_stack *current_node;
if (!stack)
return (1);
current_node = stack;
while (current_node)
{
if (current_node->value == value)
return (0);
current_node = current_node->next;
}
return (1);
}