One obvious problem here:
FILE * file = NULL;
fopen(fname, "r");
To execute fopen, you need to assign the result from fopento FILE *:
file = fopen(fname, "r");
Edit: since you are working in C, you cannot pass a pointer by reference. Alternatively, you can pass a pointer to a pointer:
int lcreate(char *fname, element **list) {
*list = malloc(sizeof(element));
(*list)->next = null;
(*list)->val = c;
}
, lcreate *list, list. , main - : list = lcreate("list.txt", list);