-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
41 lines (38 loc) · 1.31 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
/* ************************************************************************** */
/* LE - / */
/* / */
/* ft_atoi.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: thperchi <[email protected]> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/07/08 01:57:43 by thperchi #+# ## ## #+# */
/* Updated: 2018/10/10 17:58:58 by thperchi ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int x;
int y;
int z;
x = 0;
y = 0;
z = 0;
while (str[x] == ' ' || (str[x] >= 9 && str[x] <= 13))
x++;
if (str[x] == '-' || str[x] == '+')
{
if (str[x] == '-')
z = 1;
x++;
}
while ((str[x] >= '0' && str[x] <= '9'))
{
y = y * 10 + str[x] - 48;
x++;
}
if (z == 1)
y = y * -1;
return (y);
}