-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
42 lines (39 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
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mriant <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/02 10:15:16 by mriant #+# #+# */
/* Updated: 2022/06/14 14:10:22 by mriant ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
long int result;
int ispos;
int i;
i = 0;
ispos = 1;
result = 0;
if (!nptr)
return (0);
while (ft_isspace(nptr[i]))
i ++;
if (nptr[i] == '+')
i ++;
else if (nptr[i] == '-')
{
i ++;
ispos = -1;
}
while (ft_isdigit(nptr[i]))
{
result = result * 10 + (nptr[i] - '0');
i ++;
}
result = ispos * result;
return ((int)result);
}