38 lines
1.2 KiB
C
38 lines
1.2 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_atoi.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2023/07/19 09:27:06 by adjoly #+# #+# */
|
||
|
/* Updated: 2023/07/26 09:56:29 by adjoly ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
int ft_atoi(char *str)
|
||
|
{
|
||
|
int i;
|
||
|
int neg;
|
||
|
int result;
|
||
|
|
||
|
i = 0;
|
||
|
neg = 1;
|
||
|
result = 0;
|
||
|
while (str[i] == ' ' || (str[i] >= 9 && str[i] <= 13))
|
||
|
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++;
|
||
|
}
|
||
|
result *= neg;
|
||
|
return (result);
|
||
|
}
|