-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
36 lines (33 loc) · 1.2 KB
/
ft_atoi.c
File metadata and controls
36 lines (33 loc) · 1.2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sryou <sryou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/11 16:45:26 by sryou #+# #+# */
/* Updated: 2022/03/19 10:50:27 by sryou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int res;
int sign;
while ((9 <= *str && *str <= 13) || *str == ' ')
str++;
sign = 1;
if (*str == '+' || *str == '-')
{
if (*str == '-')
sign = -1;
str++;
}
res = 0;
while (ft_isdigit(*str))
{
res = res * 10 + (*str - '0');
str++;
}
return (res * sign);
}