I need some assistance with my code. I've created the function for writing the linked list to a binary file. Now I'm trying to read in a linked list from a binary file that my write function has outputted. My attempt at trying to read in the binary file and creating the link segfaults. This is my attempt below.
What am I doing wrong?
void readlist(struct link **headptr) {
FILE *text = fopen("numbers.bin", "rb");
struct link *head = *rootptr;
while (head->next != NULL) {
struct link *newlink = (struct link*) malloc(sizeof(struct link));
fread(&newlink->val, sizeof(int), 1, text);
head->next = newlink;
head = newlink;
}
fclose(text);
}