-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
44 lines (40 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ybitton <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:21:31 by ybitton #+# #+# */
/* Updated: 2016/12/15 14:23:27 by ybitton ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_espace(int c)
{
return ((9 <= c && c <= 13) || c == 32);
}
int ft_atoi(const char *str)
{
int n;
int negatif;
negatif = 0;
n = 0;
while (ft_espace(*str))
str++;
if (*str == '+')
str++;
else if (*str == '-')
{
negatif = 1;
str++;
}
while (*str != '\0' && ft_isdigit(*str))
{
n = n * 10 + (*str++ - '0');
}
if (negatif)
return (-n);
else
return (n);
}