2022-09-27 10:29:23 -04:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* ft_atoi.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2022/09/27 16:14:34 by cchauvet #+# #+# */
|
2022-09-27 11:25:41 -04:00
|
|
|
/* Updated: 2022/09/27 16:45:19 by cchauvet ### ########.fr */
|
2022-09-27 10:29:23 -04:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "libft.h"
|
|
|
|
|
|
|
|
int ft_atoi(const char *nptr)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
int out;
|
|
|
|
int sign;
|
|
|
|
|
2022-09-27 11:25:41 -04:00
|
|
|
str = (char *) nptr;
|
2022-09-27 10:29:23 -04:00
|
|
|
out = 0;
|
2022-09-27 11:25:41 -04:00
|
|
|
while (*str == ' ')
|
2022-09-27 10:29:23 -04:00
|
|
|
str++;
|
|
|
|
sign = 1;
|
|
|
|
if (*str == '-')
|
|
|
|
{
|
|
|
|
sign = -1;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
while (ft_isdigit(*str))
|
|
|
|
{
|
|
|
|
out = 10 * out + *str - 48;
|
2022-09-27 11:25:41 -04:00
|
|
|
str++;
|
2022-09-27 10:29:23 -04:00
|
|
|
}
|
2022-09-27 11:25:41 -04:00
|
|
|
return (out * sign);
|
2022-09-27 10:29:23 -04:00
|
|
|
}
|