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

41 lines
1.3 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"
static int ft_isspace(int c)
{
return (' ' == c || '\f' == c || \
'\n' == c || '\r' == c || \
'\t' == c || '\v' == c);
}
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);
}