-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
33 lines (30 loc) · 1.23 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: gwasserf <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/15 09:00:12 by event #+# #+# */
/* Updated: 2019/06/24 11:44:42 by gwasserf ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
long long result;
long long sign;
result = 0;
sign = 1;
while (ft_isspace(*str) || (*str == '+' && ft_isdigit(*(str + 1))))
str++;
if (*str == '-' && (sign = -1))
str++;
while (*str >= '0' && *(str) <= '9')
{
result = (result * 10) + (*str - '0');
str++;
}
result *= sign;
return (int)result;
}