38 lines
555 B
C
38 lines
555 B
C
#include "philo.h"
|
|
|
|
t_philo *init(char **av)
|
|
{
|
|
t_philo *philo;
|
|
t_philo *new;
|
|
t_conditions *conditions;
|
|
int n;
|
|
int i;
|
|
|
|
n = ft_atoi(av[1]);
|
|
conditions = malloc(sizeof(t_conditions));
|
|
conditions->n_phi = n;
|
|
i = 0;
|
|
while (i < n)
|
|
{
|
|
new = malloc(sizeof(t_philo) * 1);
|
|
new->conditions = conditions;
|
|
new->philo_nbr = i + 1;
|
|
if (i > 0)
|
|
{
|
|
new->prev = philo;
|
|
philo->next = new;
|
|
}
|
|
philo = new;
|
|
i++;
|
|
}
|
|
i = 0;
|
|
while (i < n - 1)
|
|
{
|
|
philo = philo->prev;
|
|
i++;
|
|
}
|
|
philo->prev = new;
|
|
new->next = philo;
|
|
return (philo);
|
|
}
|