-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
51 lines (46 loc) · 1.44 KB
/
ft_atoi.c
File metadata and controls
51 lines (46 loc) · 1.44 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: csilva-s <csilva-s@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/23 11:21:00 by csilva-s #+# #+# */
/* Updated: 2025/08/15 19:05:28 by csilva-s ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_atoi(const char *nptr);
static int ft_isspace(int c);
static int ft_isspace(int c)
{
if (c == 32 || c == 11 || c == 9
|| c == 10 || c == 12 || c == 13)
return (1);
return (0);
}
int ft_atoi(const char *nptr)
{
int i;
int signal;
int result;
i = 0;
signal = 1;
result = 0;
while (ft_isspace(nptr[i]))
i++;
if (nptr[i] == '+' && nptr[i + 1] != '-')
i++;
if (nptr[i] == '-')
{
i++;
signal *= -1;
}
while (nptr[i] && ft_isdigit (nptr[i]))
{
result *= 10;
result += nptr[i] - '0';
i++;
}
return (result * signal);
}