36 lines
1.2 KiB
C
36 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_atoi_len.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2015/11/27 19:18:43 by gbrochar #+# #+# */
|
|
/* Updated: 2016/05/06 11:45:55 by gbrochar ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
int ft_atoi_len(char *str, int *len)
|
|
{
|
|
int result;
|
|
int sign;
|
|
|
|
result = 0;
|
|
*len = 0;
|
|
sign = (*str == '-') ? -1 : 1;
|
|
if (*str == '-' || *str == '+')
|
|
{
|
|
str++;
|
|
len++;
|
|
}
|
|
while (*str >= '0' && *str <= '9')
|
|
{
|
|
result = (result * 10) + (*str - '0');
|
|
str++;
|
|
len++;
|
|
}
|
|
return (result * sign);
|
|
}
|