This is a rough idea of what I am doing:
Map map;
create_map(map); //initialize map
Value x,y;
while(...){
...
x = ...;
y = ...;
put(map, x, (void *) &y);
...
}
Map is of type {Value, (void *)}. The Map is custom written but I did not write it. I am trying to figure out where it is defined and will update if I find it. All the map does is store the association of a Value and a (void *) in a struct of some sort.
I think what is going on is that the value, y, inserted into the map is not getting the value I want. It is storing whatever value y is after the while loop executes. I want the address of each iteration to be different and pointing to a different version of y.
So with the code above, for any key X in the map, they all point to the same value. I want them to point to different values.
To do what you want, you will need to allocate different copies of “Value”, something like this:
Just don’t forget to deallocate at the end.