-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
42 lines (39 loc) · 1.37 KB
/
Copy pathft_atoi.c
File metadata and controls
42 lines (39 loc) · 1.37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfrigo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/02 13:08:25 by rfrigo #+# #+# */
/* Updated: 2018/12/02 15:22:32 by rfrigo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int i;
long int result;
long int neg;
i = 0;
neg = 1;
result = 0;
while (str[i] == ' ' || str[i] == '\v' || str[i] == '\n' ||
str[i] == '\r' || str[i] == '\t' || str[i] == '\f')
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
neg = -1;
i++;
}
while (str[i])
{
if (str[i] < '0' || str[i] > '9')
return (result * neg);
else
result = (result * 10) + (long int)(str[i] - '0');
i++;
}
return (result * neg);
}