-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
executable file
·35 lines (32 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/18 17:53:15 by akharrou #+# #+# */
/* Updated: 2019/04/30 09:25:02 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Includes/macros_42.h"
int ft_atoi(const char *str)
{
int sign;
int val;
int i;
i = 0;
while ((str[i] >= '\a' && str[i] <= '\r') || str[i] == ' ')
i++;
sign = (str[i] == '-') ? -1 : 1;
if (str[i] == '-' || str[i] == '+')
i++;
val = 0;
while (str[i] >= '0' && str[i] <= '9')
{
if (val > INT_MAX || val < INT_MIN)
return (0);
val = (val * 10) + (str[i++] - '0');
}
return (val * sign);
}