1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.

38 lines
1.3 KiB
C
Raw Permalink Normal View History

2023-08-06 20:12:38 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/25 13:48:15 by ajoly #+# #+# */
/* Updated: 2022/07/25 13:48:19 by ajoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(char *str)
{
int i;
int result;
int neg;
i = 0;
neg = 1;
result = 0;
while (str[i] == ' ' || str[i] == '\t' || str[i] == '\r'
|| str[i] == '\n' || str[i] == '\v' || str[i] == '\f')
i++;
while (str[i] == '+' || str[i] == '-')
{
if (str[i] == '-')
neg *= -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
result = result * 10 + (str[i] - 48);
i++;
}
return (result * neg);
}