-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
executable file
·40 lines (37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achambon <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/25 14:26:32 by achambon #+# #+# */
/* Updated: 2017/01/06 14:25:23 by achambon ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int i;
int result;
int posneg;
posneg = 1;
i = 0;
result = 0;
while (ft_isspace(str[i]) == 1)
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
posneg = (-1);
i++;
}
while (str[i] != '\0')
{
if (str[i] < '0' || str[i] > '9')
return (result * posneg);
result = (result * 10) + (str[i] - '0');
i++;
}
return (result * posneg);
}