-
Notifications
You must be signed in to change notification settings - Fork 0
/
fractol_utils.c
88 lines (78 loc) · 1.82 KB
/
fractol_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractol_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oumimoun <oumimoun@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 11:11:30 by oumimoun #+# #+# */
/* Updated: 2024/02/03 13:08:12 by oumimoun ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while (s1[i] == s2[i] && s1[i] && s2[i])
i++;
return (s1[i] - s2[i]);
}
void ft_print_error(char *str)
{
int i;
i = 0;
write(2, "\033[0;31m", 8);
while (str[i])
{
write(2, &str[i], 1);
i++;
}
write(2, "\033[0m", 5);
write(2, "\n", 1);
exit(1);
}
int ft_is_numerique(char c)
{
if (c >= '0' && c <= '9')
return (1);
return (0);
}
int ft_arg_is_valid(char *str)
{
int i;
i = 0;
while (str[i])
{
if (ft_is_numerique(str[i]))
i++;
else if (str[i] == '+')
i++;
else if (str[i] == '-')
i++;
else if (str[i] == '.')
i++;
else if (str[i] == ' ')
i++;
else
ft_print_error("Try using ./fractol <M or J>");
}
return (1);
}
void ft_check_double_point(char *str)
{
int i;
int flag;
i = 0;
flag = 0;
while (str[i])
{
if (str[i] == '.')
{
flag++;
if (flag > 1)
ft_print_error("Try using ./fractol <M or J>");
}
i++;
}
}