blob: 2f125bf9d0a4f414679b8375ed4cb41085835a65 (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: exam <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/26 11:11:42 by exam #+# #+# */
/* Updated: 2019/07/26 11:32:51 by exam ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *str)
{
int nb;
int is_negative;
while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r'
|| *str == '\v' || *str == '\f'|| *str == '\r')
str++;
is_negative = 0;
if (*str == '+' || *str == '-')
{
if (*str == '-')
is_negative = 1;
str++;
}
nb = 0;
while (*str >= '0' && *str <= '9')
{
nb *= 10;
nb += *str - '0';
str++;
}
if (is_negative)
nb = -nb;
return (nb);
}
|