wip_parsing
This commit is contained in:
40
libft/str/ft_atoi.c
Normal file
40
libft/str/ft_atoi.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/30 15:05:03 by madumerg #+# #+# */
|
||||
/* Updated: 2024/03/26 16:17:58 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
int i;
|
||||
int r;
|
||||
int s;
|
||||
|
||||
i = 0;
|
||||
r = 0;
|
||||
s = 1;
|
||||
if (!str)
|
||||
return (0);
|
||||
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
|
||||
i++;
|
||||
if (str[i] == '-' || str[i] == '+')
|
||||
{
|
||||
if (str[i] == '-')
|
||||
s = -1;
|
||||
i++;
|
||||
}
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
{
|
||||
r = r * 10 + str[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return (r *= s);
|
||||
}
|
Reference in New Issue
Block a user