aboutsummaryrefslogtreecommitdiff
path: root/philo/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'philo/src/main.c')
-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[])