-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
39 lines (36 loc) · 1.31 KB
/
ft_atoi.c
File metadata and controls
39 lines (36 loc) · 1.31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: muganiev <gf.black.tv@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/16 14:39:48 by muganiev #+# #+# */
/* Updated: 2022/05/31 19:31:46 by muganiev ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int i;
int is_neg;
int res;
is_neg = 1;
i = 0;
if (!str)
return (0);
while (str[i] == '\t' || str[i] == '\n' || str[i] == '\v' || str[i] == '\f'
|| str[i] == '\r' || str[i] == ' ')
i++;
if (str[i] == '-')
{
is_neg = -1;
i++;
}
else if (str[i] == '+')
i++;
res = 0;
while (str[i] >= '0' && str[i] <= '9')
res = (res * 10) + (str[i++] - '0');
return (res * is_neg);
}