-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
36 lines (33 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mtan <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/21 17:40:54 by mtan #+# #+# */
/* Updated: 2018/02/21 17:41:09 by mtan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int n;
int i;
int sign;
int count;
n = 0;
i = 0;
sign = 1;
count = 1;
while (ft_iswspace(str[i]))
i++;
if (str[i] == '-' || str[i] == '+')
{
sign = (str[i] == '-') ? (-1) : 1;
i++;
}
while (str[i] >= '0' && str[i] <= '9' && count++)
n = (n * 10) + (str[i++] - '0');
return (n * sign);
}