I am a newbie at programming at C and I am learning from a book so I apologize if the following is too basic. I am trying to implement first-class linked lists and the following program when executed gives me the error "Segmentation fault: 11".
#include <stdlib.h>
typedef struct node* link;
typedef struct node {int item; link next;} node;
typedef struct linked_list {link head; link tail;} linked_list;
int main(void)
{
link x;
x = malloc(sizeof(node));
x->next = NULL;
x->item = 12;
linked_list* l;
l->head = x;
}
The same program without the linked list pointer and instead just with:
linked_list l;
l.head = x;
runs just fine. However, I'll need multiple lists around so I will ultimately want the pointer and I can't seem to figure out what is going wrong. Does anyone know a possible solution? Thank you in advance.