int delete_user(const char *name, User **user_ptr_del)
{
    return retry_delete(name, user_ptr_del);
}

void remove_posts(User *curr)
{
    Post *curr_post = (Post *)curr->first_post;
    while (curr_post != NULL)
    {
        curr->first_post = curr_post->next;
        free(curr_post->date);
        free(curr_post->contents);
        free(curr_post);
        curr_post = curr->first_post;
    }
}

void remove_from_friends(User *curr, const char *name, User *user_list)
{
    for (int i = 0; i < MAX_FRIENDS; i++)
    {
        if (curr->friends[i] != NULL && strcmp(curr->friends[i]->name, name) == 0) // if user is a friend of someone else, delete
        {
            for (int j = i; j < MAX_FRIENDS - 1; j++)
            {
                if (curr->friends[j + 1] != NULL)
                {
                    curr->friends[j] = curr->friends[j + 1]; // delete and shift everything up
                }
                else
                {
                    curr->friends[j] = NULL;
                    // make the last element NULL
                }
            }
        }
    }
}

int retry_delete(const char *name, User **user_ptr_del)
{
    User *user_to_del = find_user(name, *user_ptr_del);
    if (user_to_del == NULL)
    {
        // user was not found
        return 1;
    }
    remove_posts(user_to_del);
    remove_from_friends(user_to_del, name, *user_ptr_del);
    if (*user_ptr_del == user_to_del)
    {
        *user_ptr_del = user_to_del->next;
        free(user_to_del);
    }
    else
    {
        User *prev = *user_ptr_del;
        while (prev->next != user_to_del)
        {
            prev = prev->next;
        }
        prev->next = user_to_del->next;
        free(user_to_del);
    }
    return 0;
}
delete user for friend's friend array