-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
57 lines (52 loc) · 1.42 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
49
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: seozkan <seozkan@student.42kocaeli.com. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/15 13:36:17 by seozkan #+# #+# */
/* Updated: 2022/12/15 16:11:03 by seozkan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isspace(int c)
{
if (c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f'
|| c == '\r')
{
return (1);
}
return (0);
}
int ft_sign(int c)
{
if (c == '+' || c == '-')
{
return (1);
}
return (0);
}
int ft_atoi(const char *str)
{
int c;
int mark;
int res;
c = 0;
mark = 1;
res = 0;
while (ft_isspace(str[c]) == 1)
c++;
if (ft_sign(str[c]) == 1)
{
if (str[c] == '-')
mark *= -1;
c++;
}
while (ft_isdigit(str[c]) == 1)
{
res = (res * 10) + (str[c] - '0');
c++;
}
return (res * mark);
}