-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
38 lines (36 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmita <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/17 17:18:27 by mmita #+# #+# */
/* Updated: 2022/12/08 18:35:55 by mmita ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
/*
def
*/
int ft_atoi(const char *str)
{
int sign;
long long value;
sign = 1;
value = 0;
while (*str == ' ' || *str == '\f' || *str == '\n'
|| *str == '\r' || *str == '\t' || *str == '\v')
str++;
if (*str == '-')
sign = -1;
if (*str == '-' || *str == '+')
str++;
while (ft_isdigit(*str))
{
value = value * 10 + (*str - '0');
str++;
}
return (value * sign);
}