37 lines
1.1 KiB
C
37 lines
1.1 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_atoi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/09/27 16:14:34 by cchauvet #+# #+# */
|
|
/* Updated: 2022/09/27 16:22:36 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
int ft_atoi(const char *nptr)
|
|
{
|
|
char *str;
|
|
int out;
|
|
int sign;
|
|
|
|
out = 0;
|
|
while (*str == " ")
|
|
str++;
|
|
sign = 1;
|
|
if (*str == '-')
|
|
{
|
|
sign = -1;
|
|
str++;
|
|
}
|
|
while (ft_isdigit(*str))
|
|
{
|
|
out = 10 * out + *str - 48;
|
|
*str++;
|
|
}
|
|
return (out * sign)
|
|
}
|