libft_old/extended_libft/ft_atoi.c
Willem Haffmans 326f52308e all
2024-07-26 22:32:04 +02:00

34 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/05 18:42:02 by whaffman #+# #+# */
/* Updated: 2024/07/09 22:20:16 by whaffman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
int sign;
int res;
while (ft_isspace(*nptr))
nptr++;
res = 0;
sign = 1;
while (*nptr == '-' || *nptr == '+')
{
if (*nptr == '-')
sign *= -1;
nptr++;
}
while (ft_isdigit(*nptr))
res = 10 * res + sign * (*nptr++ - '0');
return (res);
}