33 lines
1.2 KiB
C
33 lines
1.2 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_atoi.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2015/11/27 19:18:43 by gbrochar #+# #+# */
|
||
|
/* Updated: 2015/12/05 15:01:36 by gbrochar ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
#include "libft.h"
|
||
|
|
||
|
int ft_atoi(const char *str)
|
||
|
{
|
||
|
long result;
|
||
|
long sign;
|
||
|
|
||
|
result = 0;
|
||
|
while (ft_isspace(*str))
|
||
|
str++;
|
||
|
sign = (*str == '-') ? -1 : 1;
|
||
|
if (*str == '-' || *str == '+')
|
||
|
str++;
|
||
|
while (*str >= '0' && *str <= '9')
|
||
|
{
|
||
|
result = (result * 10) + (*str - '0');
|
||
|
str++;
|
||
|
}
|
||
|
return ((int)(result * sign));
|
||
|
}
|