diff options
| author | Dominik Kaiser | 2025-01-17 12:06:21 +0100 |
|---|---|---|
| committer | Dominik Kaiser | 2025-01-17 12:06:21 +0100 |
| commit | ed1c486272f06d977d308a8bcaaa4b1dac12b6d7 (patch) | |
| tree | 153e37e19b5c2e540104753240f89af0c4c07852 /philo/src/ft_utils.c | |
| parent | 7f62b82b1fcf64b1bb4fc6e536706a91ed99c492 (diff) | |
| download | Philosophers-ed1c486272f06d977d308a8bcaaa4b1dac12b6d7.tar.gz Philosophers-ed1c486272f06d977d308a8bcaaa4b1dac12b6d7.zip | |
Add ft_utils
Diffstat (limited to 'philo/src/ft_utils.c')
| -rw-r--r-- | philo/src/ft_utils.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/philo/src/ft_utils.c b/philo/src/ft_utils.c new file mode 100644 index 0000000..9eb660a --- /dev/null +++ b/philo/src/ft_utils.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/17 11:57:11 by dkaiser #+# #+# */ +/* Updated: 2025/01/17 11:59:28 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_utils.h" + +int ft_err(const char *str) +{ + printf("\e[31m[ERROR] %s\e[0m\n", str); + return (EXIT_FAILURE); +} + +int ft_atoi(const char *str) +{ + int 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); +} |
