38 lines
1.3 KiB
C
38 lines
1.3 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* 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);
|
||
|
}
|