-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathft_atoi.c
33 lines (31 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tsomsa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/22 13:06:01 by tsomsa #+# #+# */
/* Updated: 2022/02/22 13:12:25 by tsomsa ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nb)
{
int prefix;
int number;
number = 0;
if (*nb == '\0' || *nb == '\e')
return (0);
while (*nb <= 32)
nb++;
if (*nb == '-')
prefix = -1;
else
prefix = 1;
if (*nb == '-' || *nb == '+')
nb++;
while (ft_isdigit(*nb))
number = (number * 10) + (*nb++ - '0');
return (prefix * number);
}