-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_1_inspect_utils.c
80 lines (73 loc) · 1.77 KB
/
1_1_inspect_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 1_1_inspect_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anhigo-s <anhigo-s@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/16 23:48:45 by anhigo-s #+# #+# */
/* Updated: 2022/03/28 16:39:00 by anhigo-s ### ########.fr */
/* */
/* ************************************************************************** */
#include "philosophers.h"
static int ft_isdigit(int c);
static int ft_isspace(int c);
int inspect_char(int c)
{
if (ft_isdigit(c) || c == '-')
{
return (0);
}
else
{
return (1);
}
}
static int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
{
return (1);
}
else
{
return (0);
}
}
int ft_atoi(const char *str)
{
size_t number;
int sign;
int index;
number = 0;
sign = 1;
index = 0;
while (ft_isspace(str[index]))
index++;
if (str[index] == '-' || str[index] == '+')
{
if (str[index++] == '-')
sign = -1;
}
while (str[index] >= '0' && str[index] <= '9')
{
number = number * 10 + (str[index] - '0');
index++;
if (number > 2147483647 && sign == 1)
return (-1);
if (number > 2147483648 && sign == -1)
return (0);
}
return (sign * (int)number);
}
static int ft_isspace(int c)
{
if ((c >= 9 && c <= 13) || c == ' ')
{
return (1);
}
else
{
return (0);
}
}