From 0d910cd1b5e3b40ef91c4ee5334305530015a181 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Fri, 17 Jan 2025 12:40:20 +0100 Subject: [PATCH] Add loading data from args --- philo/Makefile | 2 +- philo/include/ft_utils.h | 7 +++++-- philo/src/main.c | 26 ++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/philo/Makefile b/philo/Makefile index b3af4fb..1841707 100644 --- a/philo/Makefile +++ b/philo/Makefile @@ -9,7 +9,7 @@ CFLAGS = -Wall -Wextra -Werror HEADERS = -Iinclude VPATH := src -SRC := main.c +SRC := main.c ft_utils.c OBJ_DIR := _obj OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o)) diff --git a/philo/include/ft_utils.h b/philo/include/ft_utils.h index 64804c2..3c9bd69 100644 --- a/philo/include/ft_utils.h +++ b/philo/include/ft_utils.h @@ -6,12 +6,15 @@ /* By: dkaiser +# include /* ** Prints error message and returns EXIT_FAILURE diff --git a/philo/src/main.c b/philo/src/main.c index efcc9a5..e3b90ab 100644 --- a/philo/src/main.c +++ b/philo/src/main.c @@ -6,16 +6,34 @@ /* By: dkaiser nbr_of_philos = ft_atoi(argv[1]); + data->time_to_die = ft_atoi(argv[2]); + data->time_to_eat = ft_atoi(argv[3]); + data->time_to_sleep = ft_atoi(argv[4]); + if (argc == 6) + data->times_must_eat = ft_atoi(argv[2]); + else + data->times_must_eat = 0; + if (data->nbr_of_philos <= 0) + return (ft_err("Must have at least one philosopher")); + if (data->time_to_die < 0) + return (ft_err("ttd can't be negative")); + if (data->time_to_eat < 0) + return (ft_err("tte can't be negative")); + if (data->time_to_sleep < 0) + return (ft_err("tts can't be negative")); + if (data->times_must_eat < 0) + data->times_must_eat = 0; + return (EXIT_SUCCESS); } int main(int argc, char *argv[]) -- 2.47.2