-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutils_libft.c
64 lines (58 loc) · 1.55 KB
/
outils_libft.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* outils_libft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amaach <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/05 11:55:38 by amaach #+# #+# */
/* Updated: 2021/11/05 11:55:48 by amaach ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
int ft_isdigit(int c)
{
if (c > 47 && c < 58)
return (1);
return (0);
}
int ft_is_alldigit(char *str)
{
int i;
i = 0;
if (str[i] == '\0')
return (0);
while (str[i] != '\0')
{
if (!ft_isdigit(str[i]))
return (0);
i++;
}
return (1);
}
int ft_atoi(const char *s)
{
int x;
int t;
x = 0;
t = 1;
if (!*s)
return (0);
while (*s == ' ' || *s <= '\n' || *s == '\v' || *s == '\r'
|| *s == '\t' || *s == '\f')
s++;
if (*s == '-')
t *= -1;
if (*s == '+' || *s == '-')
s++;
while (*s >= '0' && *s <= '9' && *s)
{
if (t > 0 && x < 0)
return (-1);
if (t < 0 && x < 0)
return (0);
x = (x * 10) + *s - '0';
s++;
}
return (x * t);
}