-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
48 lines (44 loc) · 1.34 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: sahafid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/05 08:51:33 by sahafid #+# #+# */
/* Updated: 2021/11/07 10:33:24 by sahafid ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isspace(const char *a)
{
return (*a == '\t'
|| *a == '\n'
|| *a == '\v'
|| *a == '\f'
|| *a == '\r'
|| *a == ' ');
}
int ft_atoi(const char *str)
{
char *a;
int i;
int res;
int sign;
a = (char *)str;
i = 0;
res = 0;
sign = 1;
while (ft_isspace(&a[i]))
i++;
if (a[i] == '-')
{
sign = -1;
i++;
}
else if (a[i] == '+')
i++;
while (a[i] >= '0' && a[i] <= '9')
res = res * 10 + a[i++] - '0';
return (res * sign);
}