-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
executable file
·35 lines (33 loc) · 1.31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aemebiku <aemebiku@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/06/26 15:33:03 by aemebiku #+# #+# */
/* Updated: 2014/06/26 15:33:04 by aemebiku ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *str)
{
int i;
int n;
int signe;
i = 0;
n = 0;
signe = 1;
if (!str)
return (0);
while (str[i] == ' ' || str[i] == '\v' || str[i] == '\t' || str[i] == '\r'
|| str[i] == '\f' || str[i] == '\n')
i++;
signe = (str[i] == '-') ? -signe : signe;
i = (str[i] == '-' || str[i] == '+') ? i + 1 : i;
while (str[i] && str[i] > 47 && str[i] < 58)
{
n = n * 10 + (str[i] - 48);
i++;
}
return (n * signe);
}