-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathft_atoi.c
45 lines (42 loc) · 1.29 KB
/
ft_atoi.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tbrowang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/18 20:14:42 by tbrowang #+# #+# */
/* Updated: 2021/07/18 20:14:56 by tbrowang ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isspace(char c)
{
if ((c >= '\t' && c <= '\r') || c == ' ')
return (1);
return (0);
}
int ft_atoi(const char *str)
{
int nb;
int i;
int min;
nb = 0;
i = 0;
min = 0;
while (str[i] == ' ')
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
min++;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
nb = nb * 10 + str[i] - '0';
i++;
}
if (min > 0)
nb = nb * -1;
return (nb);
}