diff options
| author | Dominik Kaiser | 2024-04-29 16:29:35 +0200 |
|---|---|---|
| committer | Dominik Kaiser | 2024-04-29 16:29:35 +0200 |
| commit | ee25ab14caeb40f66a5e70af92e34de73bd245fa (patch) | |
| tree | 40434685f382ae68f0d564d6d80982c9ff07fce7 | |
| parent | 44f49e00f6362c559ee575cc96bb46ffe56bf08c (diff) | |
| download | libft-ee25ab14caeb40f66a5e70af92e34de73bd245fa.tar.gz libft-ee25ab14caeb40f66a5e70af92e34de73bd245fa.zip | |
Add ft_atol.c
| -rw-r--r-- | Makefile | 3 | ||||
| -rw-r--r-- | ft_atol.c | 41 |
2 files changed, 43 insertions, 1 deletions
@@ -41,7 +41,8 @@ SRC_FILES = ft_atoi.c \ ft_printhex.c \ ft_printaddr.c \ get_next_line.c \ - get_next_line_utils.c + get_next_line_utils.c \ + ft_atol.c OBJ_FILES = $(SRC_FILES:.c=.o) diff --git a/ft_atol.c b/ft_atol.c new file mode 100644 index 0000000..8184301 --- /dev/null +++ b/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/26 17:56:54 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.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); +} |
