The non-standard strdup function does two things: it allocates dynamic memory and it copies the string. It is the very same thing as calling malloc followed by a call to strcpy (which is why strdup is a 100% superfluous function).
When you do
strcpy(list[list_size],test)
, list isn't pointing at any allocated memory - it is pointing at a random memory location anywhere in the memory. You try to copy data into this random location and get a crash.You allocate memory and point at it with
test
. Then you forget all about that memory when you lettest
point atfile
instead, you have created a memory leak. And once you have done that, you do the very same bug as in 1, since the variablestest
andfile
have nothing to do withlist
.Same bug as in 1 and 2.
I would advise studying pointers and arrays a bit more before diving into dynamic memory allocation and string handling.