Files
42_INT_08_philosophers/srcs/generic.c
2022-01-26 15:33:29 +01:00

42 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* generic.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/26 15:30:19 by hulamy #+# #+# */
/* Updated: 2022/01/26 15:31:15 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
int ft_atoi(const char *str)
{
int i;
int result;
int is_negative;
is_negative = 0;
result = 0;
i = 0;
while (str[i] == ' ' || (str[i] >= 9 && str[i] <= 13))
i++;
if (str[i] == '+')
i++;
else if (str[i] == '-')
{
is_negative = 1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
result = (result * 10) + (str[i] - '0');
i++;
}
if (is_negative)
result = result * -1;
return (result);
}