-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
37 lines (34 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
33
34
35
36
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mlegeay <mlegeay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/18 05:44:32 by mlegeay #+# #+# */
/* Updated: 2017/05/18 06:33:54 by mlegeay ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
long ft_atoi(const char *str)
{
long sign;
long nbr;
sign = 1;
while (*str == ' ' || *str == '\f' || *str == '\n' || *str == '\r' ||
*str == '\t' || *str == '\v')
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
sign = -1;
str++;
}
nbr = 0;
while (ft_isdigit((int)*str))
{
nbr = nbr * 10 + *str - '0';
str++;
}
return (sign * nbr);
}