maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_atol.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_atol.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: rmikhayl <marvin@42.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/05/13 14:53:55 by rmikhayl #+# #+# */
9/* Updated: 2024/05/13 14:54:01 by rmikhayl ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "libft.h"
14
15long ft_atol(const char *nptr)
16{
17 int i;
18 int neg;
19 long res;
20
21 i = 0;
22 neg = 1;
23 res = 0;
24 while (nptr[i] == '\t' || nptr[i] == '\v' || nptr[i] == '\n'
25 || nptr[i] == '\f' || nptr[i] == '\r' || nptr[i] == ' ')
26 i++;
27 if (nptr[i] == '-' || nptr[i] == '+')
28 {
29 if (nptr[i] == '-')
30 neg = -neg;
31 i++;
32 }
33 while (nptr[i] >= '0' && nptr[i] <= '9')
34 res = res * 10 + (nptr[i++] - 48);
35 return (res * neg);
36}
long ft_atol(const char *nptr)
Definition ft_atol.c:15