struct node {
void *info;
struct node *nextNode;
}
struct linked {
struct node* Head;
struct node* Tail;
}
struct linked* pro[32]
void initialize_list()
printf("seg 1\n");
for (int i = 0; i < 32; i++) {
if(!(pro[i] = (struct linked *) malloc(sizeof(struct linked)))) {
pro[i]->Head = pro[i]->Tail = NULL;
}
}
printf("seg 2\n");
}
I don't know why but when I call the initialize_list() function in main
int main() {
initialize_list();
}
I sometimes get the output:
seg 1
segmentation fault
and sometimes
seg 1
seg 2
What I mean by sometimes, is that when I run the program for 8 times lets say, it might run with the correct output in 6 runs and in 2 runs it might produce the segmentation fault output. Can you help me try to figure out what is wrong with this initialization? and why is it making some memory leaks I suppose?