this is my student struct with the information I read in via binary
typedef struct student_t {
//data in here
} student_t;
this is how I have declared them in main
double_linkedlist_t* listPtr;
student_t students;
node_t* node = NULLL;
this is how my file is initializzed
FILE *file;
printf("What file would you like to select?\n");
fgets( filename, MAX_NAME_LENGTH, stdin );
strtok(filename, "\n");
fflush(stdin);
file = fopen(filename, "rb+wb");
This is what my fwrite looks like in my main. I keep getting a segmentation fault and all the examples that I have seen on how to write a doubly linked list to a binary file have you do this. So I come here for an explanation on why or maybe some changes to what I have. I also have my doubly linked list declared as listPtr in main, and my node as node.
this is my Init
node_t* Init_Node( student_t data )
{
node_t* node = (node_t*) malloc( sizeof( node_t ) );
node -> students = data;
node->nextPtr = NULL;
node->prevPtr = NULL;
return node;
}
this is my node struct along with the prototype to nodeinit
typedef struct node_t
{
student_t students;
struct node_t* nextPtr;
struct node_t* prevPtr;
} node_t;
//prototypes
node_t* Init_Node( student_t );
node = listPtr->headPtr; //segmentation faults here
while(node!=NULL)
{
fwrite(node, sizeof(student_t), 1, file);
node=node->nextPtr;
}
any help on why this is happening would be greatly appreciated, I have never really written to a binary file with a doubly linked list :/.