ft_printf/libft/ft_atoi.c
2024-10-15 12:43:54 +02:00

41 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* ft_atoi.c :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/10/10 17:00:13 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/10/10 17:00:13 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#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;
if (*nptr == '-' || *nptr == '+')
{
if (*nptr == '-')
sign *= -1;
nptr++;
}
while (ft_isdigit(*nptr))
res = 10 * res + sign * (*nptr++ - '0');
return (res);
}