Changing Value of Array Pointer When Passed to a Function
Posted
by
ZAX
on Stack Overflow
See other posts from Stack Overflow
or by ZAX
Published on 2012-10-10T03:32:32Z
Indexed on
2012/10/10
3:36 UTC
Read the original article
Hit count: 195
I have a function which receives both the array, and a specific instance of the array. I try to change the specific instance of the array by accessing one of its members "color", but it does not actually change it, as can be seen by debugging (checking the value of color after function runs in the main program).
I am hoping someone can help me to access this member and change it. Essentially I need the instance of the array I'm specifying to be passed by reference if nothing else, but I'm hoping there is an easier way to accomplish what I'm trying to do.
Here's the structures:
typedef struct adjEdge{
int vertex;
struct adjEdge *next;
} adjEdge;
typedef struct vertex{
int sink;
int source;
int color; //0 will be white, 1 will be grey, 5 will be black
int number;
adjEdge *nextVertex;
} vertex;
And here is the function:
void walk(vertex *vertexArray, vertex v, int source, maxPairing *head)
{
int i;
adjEdge *traverse;
int moveVertex;
int sink;
traverse = vertexArray[v.number-1].nextVertex;
if(v.color != 5 && v.sink == 5)
{
sink = v.number;
v.color = 5;
addMaxPair(head, source, sink);
}
else
{
walk(vertexArray, vertexArray[traverse->vertex-1], source, head);
}
}
In particular, v.color needs to be changed to a 5, that way later after recursion the if condition blocks it.
© Stack Overflow or respective owner