-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.c
More file actions
57 lines (51 loc) · 1.63 KB
/
errors.c
File metadata and controls
57 lines (51 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* errors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jguacide <jguacide@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/29 09:51:50 by jguacide #+# #+# */
/* Updated: 2024/03/29 10:01:59 by jguacide ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
/*** METHOD ***
* error_syntax checks for syntax errors (not a sign or digit)
* error_duplicate checks for duplicates
* free_errors frees each node in the stack
* then sets head to NULL and exits the program
*/
int error_syntax(char *s)
{
int i;
i = 0;
if (!(s[i] == '+' || s[i] == '-' || (s[i] >= '0' && s[i] <= '9')))
return (1);
if ((s[i] == '+' || s[i] == '-') && (!(s[i + 1] >= '0' && s[i + 1] <= '9')))
return (1);
while (s[++i])
{
if (!(s[i] >= '0' && s[i] <= '9'))
return (1);
}
return (0);
}
int error_duplicate(t_list *a, int n)
{
if (!a)
return (0);
while (a)
{
if (a->content == n)
return (1);
a = a->next;
}
return (0);
}
void free_errors(t_list **a)
{
ft_lstclear(a);
write(2, "Error\n", 6);
exit(1);
}