-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
41 lines (37 loc) · 1.28 KB
/
ft_atoi.c
File metadata and controls
41 lines (37 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mjusta <mjusta@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 15:46:04 by mjusta #+# #+# */
/* Updated: 2025/05/25 17:19:01 by mjusta ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_isspace(int c)
{
return ((c >= 9 && c <= 13) || c == 32);
}
int ft_atoi(const char *nptr)
{
long result;
int sign;
result = 0;
sign = 1;
while (ft_isspace(*nptr))
nptr++;
if (*nptr == '+' || *nptr == '-')
{
if (*nptr == '-')
sign = -sign;
nptr++;
}
while (ft_isdigit(*nptr))
{
result = result * 10 + (*nptr - '0');
nptr++;
}
return (sign * result);
}