You are doing several things wrong. First, you are posting an incomplete code example. We don't know what D->ppio
, D->cant
, aux->sig
, or aux->elem
are, nor do we know whether you are setting them properly in insertInDeque
.
In deque2array
:
arr = aux->elem
You probably want:
*arr = aux->elem
Otherwise, the function is returning the value stored in the last aux->elem
+ 1. It's hard to fathom how that will run without an exception if it's supposed to return a void*
.
In your tester:
pointer = pointer + i
You are modifying pointer
on every iteration of the loop. Thus pointer
on the Nth iteration of the loop is the original value of pointer
plus the sum of integers 0 to N, not the original value of pointer
plus i
as it appears it was intended. Again, it is a miracle if this code runs without an exception, since it will be reading memory beyond the bounds of the array. Given a large enough return value of numberOfElements(queue)
, this is guaranteed to produce an error.
Once you've fixed these problems, if I assume aux->elem
is what I think it is, and insertInDeque
does what I think it does, your new problem will be that you are inserting the addresses of x
, y
, and z
into the structure, not the values, so it would then make sense for your corrected test code to print the addresses of the variables. As of now, since you are reading undefined memory locations, the results are not going to make sense regardless of what is actually in the data structure.