I have this following code:
void pushInList(t_chan **chan, char *name, char *nick_user)
{
t_chan *new_channel;
(void)nick_user;
if ((new_channel = malloc(sizeof(t_chan))) == NULL)
return ;
new_channel->name = name;
new_channel->prev = (*chan);
(*chan) = new_channel;
}
display_list(t_chan *chan, int fd)
{
int i;
i = 0;
while (chan != NULL)
{
printf("list : %s\n", chan->name);
chan = chan->prev;
}
}
int create_chanel(int fd, char *buffer, t_chan **chan)
{
char *tmp;
int i;
i = 0;
if ((tmp = get_param(fd, buffer, 2, "NICK")) == NULL)
return (EXIT_FAILURE);
while ((*chan) != NULL)
{
/* FUTUR CHECK OF EXISTING CHANEL*/
(*chan) = (*chan)->prev;
}
if ((*chan) == NULL)
pushInList(chan, tmp, "Kilian");
return (EXIT_SUCCESS);
}
int main()
{
t_chan *chan;
char *test;
chan = NULL;
test = strdup("JOIN Coucou");
create_chanel(4, test, &chan);
test = strdup("JOIN Google");
create_chanel(4, test, &chan);
printf("-------------------\nlast display :\n");
display_list(chan, 4);
}
I don't understand why my list is every time NULL. I passed a pointer but in my main the list don't keep its values. Can you help me, I don't understand...
It's a chain list of channel, When a client send "Join Coucou", if the channel Coucou doesn't exist I create a new node.
Thank you in advance, Cordialy