maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_atoi.c File Reference

Go to the source code of this file.

Functions

int ft_atoi (char *str)
 

Function Documentation

◆ ft_atoi()

int ft_atoi ( char *  str)

Definition at line 20 of file ft_atoi.c.

21{
22 int sign;
23 int num;
24 int i;
25
26 sign = 1;
27 num = 0;
28 i = 0;
29 while (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r'))
30 i++;
31 if (str[i] == '-' || str[i] == '+')
32 {
33 if (str[i] == '-')
34 {
35 sign = -1;
36 }
37 i++;
38 }
39 while (str[i] >= '0' && str[i] <= '9')
40 {
41 num = num * 10 + (str[i] - '0');
42 i++;
43 }
44 return (sign * num);
45}