Possible Duplicate:
“Assignment from incompatible pointer type” warning
I have two structures, one which builds off the other. My hope is to use them together to create an adjacency list for a directed weighted graph.
Here are my structures:
typedef struct{
int v;
int edgeWeight;
struct adjEdge * next;
}adjEdge;
typedef struct{
int v;
int weight;
struct adjEdge *adj;
}vertex;
So basically the vertex adj will be null unless there is a connection to another vertex, which is the adjEdge structures function.
My issue is that when I assign a adjEdge to the vertex structure I am getting an error:
bfs.c:75: warning: assignment from incompatible pointer type
Here is part of the code. Look to it to see where the errors are actually being thrown
while((fscanf(fp, "%d %d %d", &u, &v, &w)) != EOF)
{
vertexArray[u-1].v = u;
adjEdge * newEdge;
newEdge->v = v;
newEdge->edgeWeight = w;
newEdge->next = NULL;
if(vertexArray[u-1].adj = NULL)
{
vertexArray[u-1].adj = newEdge; //error
}
else
{
adjEdge * traverse = vertexArray[u-1].adj; //error
while(traverse->next != NULL)
{
traverse = traverse->next; //error
}
traverse->next = newEdge; //error
}
}
I thought once declared in my structures I could utilize assignments like this?
The problem is in the way you have defined structures. Define them as follows and get rid of the warnings.
Hope this helps!