-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
37 lines (34 loc) · 1.2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ssalaues <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:57:58 by ssalaues #+# #+# */
/* Updated: 2016/12/12 19:21:07 by ssalaues ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
long long s;
int n;
n = 1;
s = 0;
while ((*str >= 9 && *str <= 13) || *str == ' ')
str++;
if (*str == 45 || *str == 43)
{
if (*str == 45)
n = -1;
str++;
}
while (*str >= '0' && *str <= '9')
{
s = s * 10 + (*str);
s = s - '0';
str++;
}
return (n * s);
}