-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
55 lines (50 loc) · 1.48 KB
/
Copy pathft_atoi.c
File metadata and controls
55 lines (50 loc) · 1.48 KB
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
49
50
51
52
53
54
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: event <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/04 11:46:18 by event #+# #+# */
/* Updated: 2019/06/26 11:29:34 by nmncube ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_num(char c)
{
if (c >= 48 && c <= 57)
return (c);
return (0);
}
static int ft_bfound(char *c)
{
if (c[0] == '-')
return (1);
return (0);
}
int ft_atoi(const char *str)
{
int bfound;
int value;
int k;
value = 0;
bfound = 0;
k = 0;
while ((*str >= 8 && *str <= 13) || (*str == 32))
{
str++;
}
if (str[0] == '-' || str[0] == '+')
{
bfound = ft_bfound((char*)str);
str++;
}
while (ft_num(str[k]) && (str[k] != '+' || str[k] != '-') && str[k] != '\0')
{
value = (value * 10) + str[k] - 48;
k++;
}
if (bfound == 1)
value = value * -1;
return (value);
}