fix(wordlist copy): copy did not work, like at all

This commit is contained in:
Khaïs COLIN 2025-03-04 13:20:50 +01:00 committed by Khaïs COLIN
parent 5cd755b73c
commit 4bc6c1ab20

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/04 12:07:53 by khais #+# #+# */ /* Created: 2025/03/04 12:07:53 by khais #+# #+# */
/* Updated: 2025/03/04 12:15:38 by khais ### ########.fr */ /* Updated: 2025/03/04 13:31:08 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,14 +20,22 @@
t_wordlist *wordlist_copy(const t_wordlist *wordlist) t_wordlist *wordlist_copy(const t_wordlist *wordlist)
{ {
t_wordlist *outlist; t_wordlist *outlist;
t_wordlist *current;
if (wordlist == NULL) if (wordlist == NULL)
return (NULL); return (NULL);
outlist = ft_calloc(1, sizeof(t_wordlist)); outlist = ft_calloc(1, sizeof(t_wordlist));
outlist->word = worddesc_copy(wordlist->word); outlist->word = worddesc_copy(wordlist->word);
current = outlist;
while (wordlist != NULL) while (wordlist != NULL)
{ {
if (wordlist->next != NULL)
current->next = ft_calloc(1, sizeof(t_wordlist));
wordlist = wordlist->next; wordlist = wordlist->next;
current = current->next;
if (wordlist == NULL)
break ;
current->word = worddesc_copy(wordlist->word);
} }
return (outlist); return (outlist);
} }