-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
42 lines (39 loc) · 1.25 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
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmakwakw <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/09 08:13:11 by mmakwakw #+# #+# */
/* Updated: 2016/11/18 11:05:11 by mmakwakw ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *s)
{
int i;
int conv;
int res;
int neg_chk;
i = 0;
conv = 0;
neg_chk = 1;
if (s == NULL)
return (0);
if (s[i] == '-')
{
neg_chk = -1;
i++;
}
else if (s[i] == '+')
i++;
while (ft_isesc(s[i]))
i++;
while (s[i] >= 48 && s[i] <= 57)
{
conv = conv * 10 + s[i++] - 48;
}
res = conv * neg_chk;
return (res);
}