36 lines
1.2 KiB
C
Executable File
36 lines
1.2 KiB
C
Executable File
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_atoi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/07/17 13:41:15 by tomoron #+# #+# */
|
|
/* Updated: 2023/10/31 15:35:21 by tomoron ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
int ft_atoi(const char *str)
|
|
{
|
|
int res;
|
|
int inv;
|
|
|
|
res = 0;
|
|
inv = 1;
|
|
while (*str == ' ' || (*str >= '\t' && *str <= '\r'))
|
|
str++;
|
|
if (*str == '+' || *str == '-')
|
|
{
|
|
if (*str == '-')
|
|
inv *= -1;
|
|
str++;
|
|
}
|
|
while (*str >= '0' && *str <= '9')
|
|
{
|
|
res *= 10;
|
|
res += *str - '0';
|
|
str++;
|
|
}
|
|
return (res * inv);
|
|
}
|