files dans srcs sans dossier
This commit is contained in:
39
srcs/ft_atoi.c
Normal file
39
srcs/ft_atoi.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 13:54:29 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/25 13:54:35 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
long long nbr;
|
||||
int i;
|
||||
int n;
|
||||
|
||||
i = 0;
|
||||
n = 1;
|
||||
nbr = 0;
|
||||
while ((str[i] == 32) || (str[i] > 8 && str[i] < 14))
|
||||
i++;
|
||||
if (str[i] == '-')
|
||||
n = -1;
|
||||
if (str[i] == '+' || str[i] == '-')
|
||||
i++;
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
{
|
||||
if ((nbr >= 922337203685477580
|
||||
&& ((str[i] > 8 && n < 0) || (str[i] > 7 && n > 0))))
|
||||
return ((n > 0) ? -1 : 0);
|
||||
else
|
||||
nbr = nbr * 10 + (str[i++] - '0');
|
||||
}
|
||||
return (nbr * n);
|
||||
}
|
||||
Reference in New Issue
Block a user