init structs
This commit is contained in:
37
init.c
Normal file
37
init.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user