mirror of
https://github.com/guezoloic/libft.git
synced 2026-01-25 04:34:14 +00:00
30 lines
397 B
C
30 lines
397 B
C
#include "libft.h"
|
|
|
|
int ft_atoi(const char *str)
|
|
{
|
|
int value;
|
|
size_t i;
|
|
int is_negative;
|
|
|
|
value = 0;
|
|
i = 0;
|
|
is_negative = 0;
|
|
while (str[i] == ' ')
|
|
i++;
|
|
if (str[i] == '-')
|
|
{
|
|
is_negative = 1;
|
|
i++;
|
|
}
|
|
else if (str[i] == '+')
|
|
i++;
|
|
while (str[i] && ft_isdigit(str[i]))
|
|
{
|
|
value *= 10 + ((int)(str[i] - '0'));
|
|
}
|
|
if (is_negative)
|
|
return (value * -1);
|
|
else
|
|
return (value);
|
|
}
|