I tried to define a node struct which includes a node* next. I write an append(node* n) function to add a new node next to the previous one, but every time I run the code, it gives me seg fault. My code is following:
#include<stdlib.h> #include<stdio.h> typedef struct _log_t { struct _log_t* next; }log_t; void initi(log_t* l) { l = (log_t*)malloc(sizeof(log_t)); l -> next = NULL; } void append(log_t* l){ l->next = (log_t*)malloc(sizeof(log_t)); l->next->next = NULL; l = l->next; } Thanks in advance for any help!