0

In the for loop below I attempt to access an array of structures stored in another structure but I continue to get an error that says. "struct list has no member head."

list* createList(int size)
{
    list* graph = malloc(sizeof(list));
    graph->size = size;
    graph->array = malloc(size * sizeof(vertex));
    int i;
    for(i=0; i < size;i++){
        graph->array[i].head = NULL;
        return graph;
    }
}

The structures I am attempting to use are as follows.

struct vertex
{
    struct vertex *head;
};
typedef struct vertex vertex;

And

struct list
{
    int size;
    struct list* array;
};
typedef struct list list;
1
  • 1
    Your list's array member should be a struct vertex*. Otherwise, I don't see any vertex in your code. Commented Feb 12, 2014 at 21:10

2 Answers 2

2

Your list member is of type list, when it should be of type vertex.

Sign up to request clarification or add additional context in comments.

Comments

1

You don't have any references to your struct vertex in struct list. I suspect that it should be

struct list{
     int size;
     struct vertex* array;
};
typedef struct list list;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.