-
Notifications
You must be signed in to change notification settings - Fork 7
/
ft_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: vvarodi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/22 18:03:32 by vvarodi #+# #+# */
/* Updated: 2020/01/22 18:41:46 by vvarodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int num;
int sign;
num = 0;
sign = 1;
while (ft_isspace(*str))
str++;
if (*str == '-')
sign = - 1;
if (*str == '-' || *str == '+')
str++;
while (*str >= '0' && *str <= '9')
num = num * 10 + *str++ - '0';
return (num * sign);
}