use
actions[index]=strdup(tok);
instead of
actions[index]=tok;
In fact tok
is a pointer pointing to an address into the array str
. When you free str
, the tok
become pointed to an address address that already freed. So you have to keep a copy of the tok content in another memory address. strdup
allow to allocate memory and then copy the tok content in this memory
and then when your action[]
array become useless in your code do not forget to free each elemet in the array
for (i=0;i<max;i++)
free(actions[i]);