The following code in your
insert
function
head2 = (List *)malloc(sizeof(List));
head2 = head;
and
toBeInserted = (List *)malloc(sizeof(List));
toBeInserted = create(str);
are
memory leaks[
^], the first line in both instances is not needed.
You are allocating memory that is not release and to which the pointer is overwritten.
You also need to to free the memory allocated for the list at the end of your program.
In your current code you are losing text because of the
toBeInserted->next = head2->next;
statement in your insert function. the variable
toBeInserted
is the head of the list containing "very much", you need to use the last node of the list in this statement.
Hint: Each node in your list should contain a word and not just one character from the string entered. Otherwise you cannot be using 1 to add the second list to the first one.