ft_atoi: fix leading whitespace parsing

This commit is contained in:
Khaïs COLIN 2024-10-18 18:01:46 +02:00
parent 045f9a9012
commit 9b93b1c909

View file

@ -6,12 +6,25 @@
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 16:06:11 by kcolin #+# #+# */ /* Created: 2024/10/16 16:06:11 by kcolin #+# #+# */
/* Updated: 2024/10/16 16:14:38 by kcolin ### ########.fr */ /* Updated: 2024/10/18 17:58:42 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
int ft_isspace(char c)
{
if (c == ' '
|| c == '\f'
|| c == '\n'
|| c == '\r'
|| c == '\t'
|| c == '\v')
return (1);
else
return (0);
}
int ft_atoi(const char *nptr) int ft_atoi(const char *nptr)
{ {
int result; int result;
@ -19,6 +32,8 @@ int ft_atoi(const char *nptr)
result = 0; result = 0;
i = 0; i = 0;
while (ft_isspace(nptr[i]))
i++;
while (ft_isdigit(nptr[i])) while (ft_isdigit(nptr[i]))
{ {
result *= 10; result *= 10;