-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_atoi.c
32 lines (30 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vbrazas <vbrazas@student.unit.ua> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/03 20:09:38 by vbrazas #+# #+# */
/* Updated: 2018/05/24 20:20:16 by vbrazas ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *str)
{
short i;
unsigned long result;
short minus;
i = 0;
result = 0;
minus = 1;
while ((str[i] >= '\a' && str[i] <= '\r') || str[i] == 32)
i++;
if (str[i] == '-')
minus = -1;
if (str[i] == '-' || str[i] == '+')
i++;
while (str[i] >= '0' && str[i] <= '9')
result = result * 10 + (str[i++] - '0');
result = result * minus;
return ((int)result);
}