I have an initialization for a struct that I keep getting a segmentation fault: 11
for.
typedef struct {
int id;
double value;
char* name;
} Item;
typedef struct {
Item** items;
int length;
int capacity;
} List;
List* initList()
{
List* list = NULL;
list->items = (Item**)malloc(10 * sizeof(Item*));
list->length = 0;
list->capacity = 10;
return list;
}
Here in main.c
is where I get an error per GDB:
List* list = initList();
I cannot initialize, I notice because there is a problem with
list->items = (Item**)malloc(10 * sizeof(Item*));
I am new to C, but I am sure that my initList
function will create a list with the given assignments. I also have a respective function to free the items
in initList
.