Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Philosophers-42
Path: blob/master/philo/ft_initialize_philosophers.c
882 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_initialize_philosophers.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: yabtaour <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/05/19 18:03:08 by yabtaour #+# #+# */
9
/* Updated: 2022/05/19 18:03:14 by yabtaour ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
#include "philosophers.h"
13
14
void ft_initialize_philosophers(t_data *data)
15
{
16
int i;
17
18
i = 0;
19
while (i < data->philos_num)
20
{
21
data->philosopher[i].eat = 0;
22
data->philosopher[i].philo_id = i + 1;
23
data->philosopher[i].data = data;
24
data->philosopher[i].right_fork = &data->fork[i];
25
if (i == (data->philos_num - 1))
26
data->philosopher[i].left_fork = &data->fork[0];
27
else
28
data->philosopher[i].left_fork = &data->fork[i + 1];
29
i++;
30
}
31
}
32
33