Libft aortigos

This commit is contained in:
Angel Ortigosa Perez
2025-11-15 09:18:35 +01:00
commit c87ab67280
45 changed files with 1439 additions and 0 deletions

41
ft_atoi.c Normal file
View File

@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/22 20:46:43 by aortigos #+# #+# */
/* Updated: 2023/10/18 20:41:03 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int sign;
int result;
int i;
sign = 1;
result = 0;
i = 0;
while ((str[i] == ' ' || str[i] == '\t' || str[i] == '\n')
|| (str[i] == '\v' || str[i] == '\r' || str[i] == '\f'))
i++;
if (str[i] == '-')
{
sign = -1;
}
if (str[i] == '-' || str[i] == '+')
{
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
result = result * 10 + (str[i] - '0');
i++;
}
return (sign * result);
}