-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
48 lines (44 loc) · 1.37 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
39
40
41
42
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: phemsi-a <phemsi-a@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/02 02:08:07 by phemsi-a #+# #+# */
/* Updated: 2021/05/25 11:28:00 by phemsi-a ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int atoi_isspace(int c)
{
if (c == ' ' || c == '\v' || c == '\n'
|| c == '\t' || c == '\r' || c == '\f')
{
return (1);
}
return (0);
}
double ft_atoi(const char *nptr)
{
double number;
int sign;
number = 0;
sign = 1;
while (atoi_isspace(*nptr))
nptr++;
if (*nptr == '-' || *nptr == '+')
{
if (*nptr == '-')
sign *= -1;
nptr++;
}
while (ft_isdigit(*nptr))
{
number *= 10;
number += (*nptr - '0');
nptr++;
}
number *= sign;
return (number);
}