-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathft_atoi.c
More file actions
39 lines (36 loc) · 1.28 KB
/
ft_atoi.c
File metadata and controls
39 lines (36 loc) · 1.28 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: wbeets <wbeets@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/03/20 11:56:28 by wbeets #+# #+# */
/* Updated: 2015/03/20 11:56:30 by wbeets ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(char *str)
{
int is_neg;
int val;
is_neg = 0;
val = 0;
while ((*str == '\t') || (*str == '\v')
|| (*str == '\n') || (*str == '\r')
|| (*str == '\f') || (*str == ' '))
str++;
if (*str == '-')
{
is_neg = 1;
str++;
}
else if (*str == '+')
str++;
while (ft_isdigit(*str))
{
val = (val * 10) + (*str - 48) % 10;
str++;
}
return (val = is_neg ? val * -1 : val);
}