-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
35 lines (32 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpaaso <tpaaso@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/16 13:43:58 by tpaaso #+# #+# */
/* Updated: 2022/04/11 12:27:39 by tpaaso ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int result;
int sign;
result = 0;
sign = 1;
while (*str == ' ' || *str == '\f' || *str == '\n' || *str == '\r'
|| *str == '\v' || *str == '\t')
str++;
if (*str == '-')
sign = -1;
if (*str == '+' || *str == '-')
str++;
while (*str >= '0' && *str <= '9')
{
result = result * 10 + *str - '0';
str++;
}
return (result * sign);
}