/*
#ifndef FT_LIST_H
# define FT_LIST_H

typedef struct s_list
{
	struct s_list	*next;
	void			*data;
}	t_list;

#endif
*/

// variante 1 current et previous (ptr simple)
void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)())
{
    t_list *current;
    t_list *previous;

    if (begin_list == NULL || *begin_list == NULL)
        return;

    current = *begin_list;
    previous = NULL;

    while (current != NULL)
    {
        if (cmp(current->data, data_ref) == 0)
        {
            if (previous == NULL)
                *begin_list = current->next;
            else
                previous->next = current->next;

            t_list *temp = current;
            current = current->next;
            free(temp);
        }
        else
        {
            previous = current;
            current = current->next;
        }
    }
}


//variante 2: ptr sur ptr
void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)())
{
    t_list **current = begin_list;
    t_list *temp;

    while (*current)
    {
        if (cmp((*current)->data, data_ref) == 0)
        {
            temp = *current;
            *current = (*current)->next;
            free(temp);
        }
        else
        {
            current = &(*current)->next;
        }
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: