-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
40 lines (37 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abouramd <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/07 17:02:33 by abouramd #+# #+# */
/* Updated: 2022/11/19 00:19:19 by abouramd ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int sign;
long res;
long t;
sign = 1;
res = 0;
while (*str == ' ' || (*str <= 13 && *str >= 9))
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
sign = -1;
str++;
}
while (*str <= '9' && *str >= '0')
{
t = (res * 10) + (*str - '0');
if (res > t)
return (0 - (sign > 0));
res = t;
str++;
}
return (sign * res);
}