From ed1c486272f06d977d308a8bcaaa4b1dac12b6d7 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Fri, 17 Jan 2025 12:06:21 +0100 Subject: [PATCH] Add ft_utils --- philo/include/ft_utils.h | 26 ++++++++++++++++++++++ philo/include/philo.h | 34 +++++++++++++++++++++++++++++ philo/src/ft_utils.c | 47 ++++++++++++++++++++++++++++++++++++++++ philo/src/main.c | 18 +++++++++++++-- 4 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 philo/include/ft_utils.h create mode 100644 philo/include/philo.h create mode 100644 philo/src/ft_utils.c diff --git a/philo/include/ft_utils.h b/philo/include/ft_utils.h new file mode 100644 index 0000000..64804c2 --- /dev/null +++ b/philo/include/ft_utils.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_utils.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser +# include +# include +# include +# include +# include "ft_utils.h" + +# define ERR_USAGE "Usage: [times_must_eat]" + +typedef struct s_phdata +{ + int nbr_of_philos; + int time_to_die; + int time_to_eat; + int time_to_sleep; + int times_must_eat; +} t_phdata; + +#endif 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 = '\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); +} diff --git a/philo/src/main.c b/philo/src/main.c index bca80b5..efcc9a5 100644 --- a/philo/src/main.c +++ b/philo/src/main.c @@ -6,13 +6,27 @@ /* By: dkaiser