Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Philosophers-42
Path: blob/master/philo_bonus/ft_initialize_data_bonus.c
882 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_initialize_data_bonus.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: yabtaour <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/05/23 00:06:20 by yabtaour #+# #+# */
9
/* Updated: 2022/05/23 00:06:22 by yabtaour ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
#include "philosophers_bonus.h"
13
14
int ft_initialize_data(t_data *data)
15
{
16
data->philos_num = ft_atoi(data->argv[1]);
17
data->time_to_die = ft_atoi(data->argv[2]);
18
data->time_to_eat = ft_atoi(data->argv[3]);
19
data->time_to_sleep = ft_atoi(data->argv[4]);
20
data->birth = ft_timestamp();
21
data->is_dead = 0;
22
if (data->argv[5])
23
{
24
data->must_eat = ft_atoi(data->argv[5]);
25
if (data->must_eat <= 0)
26
return (0);
27
}
28
else
29
data->must_eat = -1;
30
if (data->philos_num < 1)
31
return (0);
32
return (1);
33
}
34
35