init structs

This commit is contained in:
hugogogo
2022-01-05 09:00:02 +01:00
parent 23f93e706a
commit 1c44397e61
6 changed files with 74 additions and 68 deletions

37
init.c Normal file
View 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);
}