-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
41 lines (38 loc) · 1.27 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
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: juhagon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/04 09:53:17 by juhagon #+# #+# */
/* Updated: 2022/02/04 11:49:22 by juhagon ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
int ft_atoi(const char *s)
{
long int tmp;
long int nmb;
long int sign;
tmp = 0;
nmb = 0;
sign = 0;
while (s[tmp] == 32 || (s[tmp] > 8 && s[tmp] < 14))
tmp++;
if (s[tmp] == '+')
tmp++;
else if (s[tmp] == '-')
{
tmp++;
sign = 1;
}
while (s[tmp] >= '0' && s[tmp] <= '9')
{
nmb = nmb * 10 + s[tmp] - '0';
tmp++;
}
if (sign == 1)
nmb = -nmb;
return (nmb);
}