feat: initial version
This commit is contained in:
parent
5cad2db883
commit
6428ed06b0
16 changed files with 263 additions and 0 deletions
29
srcs/ft_atoi.c
Normal file
29
srcs/ft_atoi.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
int i = 0;
|
||||
int r = 0;
|
||||
int s = 1;
|
||||
|
||||
while (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r'))
|
||||
i++;
|
||||
|
||||
if (str[i] == '-')
|
||||
{
|
||||
s = -1;
|
||||
i++;
|
||||
}
|
||||
else if (str[i] == '+')
|
||||
i++;
|
||||
|
||||
while(str[i] != '\0')
|
||||
{
|
||||
if (str[i] >= '0' && str[i] <= '9')
|
||||
r = r * 10 + str[i] - '0';
|
||||
else
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
return (s * r);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue