-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
31 lines (29 loc) · 1.18 KB
/
Copy pathft_atoi.c
File metadata and controls
31 lines (29 loc) · 1.18 KB
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: juhenriq <dev@juliohenrique.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/06 18:39:51 by juhenriq #+# #+# */
/* Updated: 2024/11/13 19:12:09 by juhenriq ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *str)
{
int num;
int sign;
sign = 1;
while ((*str >= '\t' && *str <= '\r') || *str == ' ')
str++;
num = 0;
if (*str == '-' || *str == '+')
{
if (*str == '-')
sign *= -1;
str++;
}
while (*str >= '0' && *str <= '9')
num = (num * 10) + (*str++ - '0');
return (num * sign);
}