-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
46 lines (42 loc) · 1.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marschul <marschul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/24 14:24:29 by marschul #+# #+# */
/* Updated: 2023/06/18 19:25:54 by marschul ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_isspace(char c)
{
if (c == ' ' || c == '\n' || c == '\t' || c == '\r' \
|| c == '\f' || c == '\v')
return (1);
else
return (0);
}
int ft_atoi(const char *str)
{
int nbr;
int minus;
while (ft_isspace(*str))
str++;
minus = 1;
if (*str == '+' || *str == '-')
{
if (*str == '-')
minus = -1;
str++;
}
nbr = 0;
while (*str != '\0' && ft_isdigit((int) *str))
{
nbr = 10 * nbr;
nbr += *str - '0';
str++;
}
return (minus * nbr);
}