first commit
This commit is contained in:
37
ended/C04/ex03/ft_atoi.c
Normal file
37
ended/C04/ex03/ft_atoi.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
Reference in New Issue
Block a user