maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_atol.c File Reference
#include "libft.h"
Include dependency graph for ft_atol.c:

Go to the source code of this file.

Functions

long ft_atol (const char *nptr)
 

Function Documentation

◆ ft_atol()

long ft_atol ( const char *  nptr)

Definition at line 15 of file ft_atol.c.

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}