-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
26 lines (24 loc) · 1.15 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mfebvay <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2013/11/20 19:44:33 by mfebvay #+# #+# */
/* Updated: 2015/01/20 20:01:36 by mfebvay ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *str)
{
int sum;
int sign;
sum = 0;
while ((*str >= 9 && *str <= 13) || *str == ' ')
str++;
if ((sign = (*str == '-' ? -1 : 1)) == -1 || *str == '+')
str++;
while (*str >= '0' && *str <= '9')
sum = sum * 10 + *str++ - '0';
return (sum * sign);
}