diff options
| author | Dominik Kaiser | 2024-05-08 13:14:19 +0200 |
|---|---|---|
| committer | Dominik Kaiser | 2024-05-08 13:14:19 +0200 |
| commit | 95ccc46ad62c59e648679acad8b44ba5d4465e3d (patch) | |
| tree | c053e4c692039d151cefa26759bee90d31d8c0a0 /libft/ft_atol.c | |
| parent | 42289aa55c7dafe8fffbcdfb0e02f089b7b83afb (diff) | |
| download | pipex-95ccc46ad62c59e648679acad8b44ba5d4465e3d.tar.gz pipex-95ccc46ad62c59e648679acad8b44ba5d4465e3d.zip | |
Diffstat (limited to 'libft/ft_atol.c')
| -rw-r--r-- | libft/ft_atol.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/libft/ft_atol.c b/libft/ft_atol.c new file mode 100644 index 0000000..ae47db0 --- /dev/null +++ b/libft/ft_atol.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atol.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/26 16:18:28 by dkaiser #+# #+# */ +/* Updated: 2024/04/29 16:40:38 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +long ft_atol(const char *str) +{ + long result; + int i; + int posneg; + + posneg = 1; + result = 0; + i = 0; + while ((str[i] >= '\t' && str[i] <= '\r') || str[i] == ' ') + { + i++; + } + if (str[i] == '-') + { + posneg = -1; + i++; + } + else if (str[i] == '+') + i++; + while (str[i] >= '0' && str[i] <= '9') + { + result = 10 * result + str[i] - '0'; + i++; + } + return (result * posneg); +} |
