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

View File

@@ -14,41 +14,6 @@ void *philo_exec(void *arg)
}
*/
t_philo *init(char **av)
{
t_philo *philo;
t_philo *new;
t_conditions conditions;
int n;
int i;
n = ft_atoi(av[1]);
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);
}
int main(int ac, char **av)
{
// pthread_t id;
@@ -57,21 +22,7 @@ int main(int ac, char **av)
if (ac == 1)
return (0);
philo = init(av);
int i; int n;
i = 0;
n = philo->conditions->n_phi;
ft_putnbr_fd(n, 1);
write(1, "\n\n", 2);
//while (i < n * 2 + n / 2)
while (i < philo->conditions->n_phi * 2 + 5)
{
ft_putnbr_fd(philo->conditions->n_phi, 1);
write(1, " - ", 3);
ft_putnbr_fd(philo->philo_nbr, 1);
write(1, "\n", 1);
philo = philo->prev;
i++;
}
// while (philo->n_philo)
// {
// pthread_create(&id, NULL, &philo_exec, philo);