-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
35 lines (32 loc) · 1.28 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: ashongwe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/23 08:01:31 by ashongwe #+# #+# */
/* Updated: 2019/06/14 14:30:25 by ashongwe ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int result;
int sign;
sign = 1;
result = 0;
while (*str && (*str == ' ' || *str == '\n' || *str == '\t' ||
*str == '\v' || *str == '\f' || *str == '\r'))
++str;
if (*str == '-')
sign = -1;
if (*str == '-' || *str == '+')
++str;
while (*str && *str >= '0' && *str <= '9')
{
result = result * 10 + (*str - 48);
++str;
}
return (result * sign);
}