im new to C and trying to understand some fundamental stuff. I'm trying to create a struct which holds an array that consists of linked lists. Something around this.
--------------------------------
| A | B | C |
--------------------------------
| | |
V V V
------- ------- -------
| a | | b | | c |
------- ------- -------
|
V
--------
| a1 |
--------
Meaning ill have an array which holds the head(A, B and C) of each linked list and each head will hold a pointer to the next node.
I have a struct Object
typedef struct Object {
void* data;
struct Object* next;
struct Object* head;
}Object;
And a table which holds some more info
typedef struct Table {
Object** arr;
//More info...//
}Table;
I have a function which should create a table with the array.
Table* createTable(){
Table* table = (Table*)malloc(sizeof(struct Table*));
Object **array = (Object**)malloc(3*sizeof(struct Object*));
for(int j = 0; j < size; j++){
array[j] = malloc(sizeof(struct Object));
}
table->arr = array;
return table;
}
But all my memory isn't working as i hoped for, i keep getting an array with just one node. I guess im still missing some basic stuff.
Thanks