FIX first part of mandatory functions
This commit is contained in:
29
ft_atoi.c
29
ft_atoi.c
@@ -6,7 +6,7 @@
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/05 19:07:51 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/05 19:17:34 by dgaillet ### ########lyon.fr */
|
||||
/* Updated: 2025/11/05 20:53:10 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -21,9 +21,28 @@ int ft_atoi(const char *nptr)
|
||||
res = 0;
|
||||
if (!nptr[0])
|
||||
return (0);
|
||||
if (nptr[0] == '-' && ft_isdigit(nptr[1]))
|
||||
return (-1 * ft_atoi(nptr + 1));
|
||||
while (ft_isdigit(nptr[i++]))
|
||||
res = (10 * res) + (nptr[i] - '0');
|
||||
while ((nptr[i] >= 9 && nptr[i] <= 13) || nptr[i] == ' ')
|
||||
i++;
|
||||
if (nptr[i] == '-' && ft_isdigit(nptr[i + 1]))
|
||||
return (-1 * ft_atoi(&nptr[i] + 1));
|
||||
else if (nptr[i] == '+' && ft_isdigit(nptr[i + 1]))
|
||||
i++;
|
||||
while (ft_isdigit(nptr[i]))
|
||||
{
|
||||
res = (10 * res) + nptr[i] - 48;
|
||||
i++;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
/*
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc > 1)
|
||||
{
|
||||
printf("%d\n", ft_atoi(argv[1]));
|
||||
printf("%d\n", atoi(argv[1]));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user