aboutsummaryrefslogtreecommitdiff
path: root/philo/src
diff options
context:
space:
mode:
authorDominik Kaiser2025-01-17 12:40:20 +0100
committerDominik Kaiser2025-01-17 12:40:20 +0100
commit0d910cd1b5e3b40ef91c4ee5334305530015a181 (patch)
tree413c49ffb1572b593b3b921779e8c965f29b4764 /philo/src
parent987211580c3f92cf33416edf8d71e22daaf9e65e (diff)
downloadPhilosophers-0d910cd1b5e3b40ef91c4ee5334305530015a181.tar.gz
Philosophers-0d910cd1b5e3b40ef91c4ee5334305530015a181.zip
Add loading data from args
Diffstat (limited to 'philo/src')
-rw-r--r--philo/src/main.c26
1 files changed, 22 insertions, 4 deletions
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 <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/14 17:13:30 by dkaiser #+# #+# */
-/* Updated: 2025/01/17 11:53:53 by dkaiser ### ########.fr */
+/* Updated: 2025/01/17 12:40:05 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
-int ft_err(char *str)
+
+int load_data(t_phdata *data, int argc, char *argv[])
{
- printf("\e[31m[ERROR] %s\e[0m\n", str);
- return (EXIT_FAILURE);
+ data->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[])