]> git.dkaiser.de - 42/Philosophers.git/commitdiff
Add loading data from args
authorDominik Kaiser <dkaiser@student.42heilbronn.de>
Fri, 17 Jan 2025 11:40:20 +0000 (12:40 +0100)
committerDominik Kaiser <dkaiser@student.42heilbronn.de>
Fri, 17 Jan 2025 11:40:20 +0000 (12:40 +0100)
philo/Makefile
philo/include/ft_utils.h
philo/src/main.c

index b3af4fb93a0e12dac405866e1ed5c454d9bbd4fb..1841707d34f6201ffd5c198f966c0f36cf3559d6 100644 (file)
@@ -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))
index 64804c25b942dbcdb3f259264cfef81bd022462c..3c9bd698b879062979997ab56b6a6744b174d5d3 100644 (file)
@@ -6,12 +6,15 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/01/17 11:57:44 by dkaiser           #+#    #+#             */
-/*   Updated: 2025/01/17 12:00:11 by dkaiser          ###   ########.fr       */
+/*   Updated: 2025/01/17 12:39:17 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #ifndef FT_UTILS_H
-#define FT_UTILS_H
+# define FT_UTILS_H
+
+# include <stdlib.h>
+# include <stdio.h>
 
 /*
 ** Prints error message and returns EXIT_FAILURE
index efcc9a583fca3e41028b3a8eb537527c5f1d65f1..e3b90ab7970aa64f485b09bee8c9a7b9b28c1bde 100644 (file)
@@ -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[])