29 lines
No EOL
472 B
C
29 lines
No EOL
472 B
C
#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);
|
|
} |