-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
37 lines (34 loc) · 1.26 KB
/
Copy pathft_atoi.c
File metadata and controls
37 lines (34 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: josfelip <josfelip@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/30 13:41:18 by josfelip #+# #+# */
/* Updated: 2023/08/07 13:49:54 by josfelip ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
int sign;
int nb;
sign = 1;
nb = 0;
while (*nptr == '\t' || *nptr == '\n' || *nptr == '\v' || \
*nptr == '\f' || *nptr == '\r' || *nptr == ' ')
nptr++;
if (*nptr == '-' || *nptr == '+')
{
if (*nptr == '-')
sign = -1;
nptr++;
}
while (ft_isdigit(*nptr))
{
nb = (*nptr - '0') + (nb * 10);
nptr++;
}
return (nb * sign);
}