In the function list2listarray
you pass the variable orderarray
by reference (or as close as it can be in C) to the addtoken
function, so when you do *start = tmp
in the addtoken
function you actually change the pointer in the list2listarray
function as well, loosing your initial pointer you allocated there.
You also have a problem in list2listarray
with your tmp++
as that makes you loose the original pointer as well.
There is no need to pass this pointer "by reference" to the addtoken
function, or to allocate there in the first place.
There are probably more problems related to your pointer use in the shown code, most likely leading to undefined behavior. I recommend you turn on more warnings by the compiler, as those are a good way to find possible places where you have undefined behavior, but don't just add casting as a way to shut the warnings up as it probably don't solve the actual root cause. And talking about casting, don't cast the return of malloc
.