-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_2.c
More file actions
67 lines (61 loc) · 1.71 KB
/
utils_2.c
File metadata and controls
67 lines (61 loc) · 1.71 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ymassiou <ymassiou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 20:28:35 by ymassiou #+# #+# */
/* Updated: 2024/02/11 18:15:06 by ymassiou ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void ft_putstr_fd(char *s, int fd)
{
if (s == NULL)
return ;
if (fd >= 0)
{
while (*s)
write(fd, s++, 1);
}
}
int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
return (1);
return (0);
}
int ft_check(char c)
{
if (c == '+' || c == '-' || ft_isdigit(c) || c == '.')
return (1);
return (0);
}
int check_input(char *str)
{
int i;
int count_digit;
int count_dot;
i = -1;
count_digit = 0;
count_dot = 0;
while (str[++i])
{
if (!ft_check(str[i]))
return (0);
else if (ft_isdigit(str[i]) && (str[i + 1] == '+' || str[i + 1] == '-'))
return (0);
if ((str[i] == '+' || str[i] == '-') && !ft_isdigit(str[i + 1]))
return (0);
if (str[i] >= '0' && str[i] <= '9')
count_digit++;
if (str[i] == '.')
count_dot++;
}
if (count_digit == 0)
return (0);
if (count_dot > 1)
return (0);
return (1);
}