-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
executable file
·35 lines (32 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kbensado <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/10/15 00:18:14 by kbensado #+# #+# */
/* Updated: 2015/12/30 12:52:21 by kbensado ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int signe;
int nb;
int i;
i = 0;
nb = 0;
while (str[i] == ' ' || str[i] == '\n' || str[i] == '\t'
|| str[i] == '\r' || str[i] == '\f' || str[i] == '\v')
i++;
signe = (str[i] == '-' ? -1 : 1);
if (str[i] == '-' || str[i] == '+')
i++;
while (str[i] && str[i] <= '9' && str[i] >= '0')
{
nb = nb * 10 + (str[i] - '0');
i++;
}
return (signe * nb);
}