-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
31 lines (28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: almarcos <almarcos@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/26 15:15:31 by almarcos #+# #+# */
/* Updated: 2023/10/09 11:52:14 by almarcos ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int result;
int sign;
int i;
result = 0;
sign = 1;
i = 0;
while (str[i] == ' ' || (str[i] >= 9 && str[i] <= 13))
i++;
if (str[i] == '-' || str[i] == '+')
sign = 1 - 2 * (str[i++] == '-');
while (ft_isdigit(str[i]))
result = 10 * result + (str[i++] - '0');
return (result * sign);
}