I don't know if this is going to help you. I had a similar problem last year. I modified my code to help you so here it is:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node{
int len;
int* msg;
struct node* next;
}Node,*pNode;
int main(int argc, char **argv)
{
int i;
pNode n,m;
int array[]={1,2,3,4,5};
FILE* fp= fopen("Test.bin","wb");
if(!fp)
{
fprintf(stderr,"Error!");
return 0;
}
n=(pNode)malloc(sizeof(Node));
n->msg=(int*)malloc(sizeof(int)*5);
memcpy(n->msg,array,sizeof(int)*5);
n->len=5;
n->next=NULL;
fwrite(&(n->len),sizeof(n->len),1,fp);
for(i=0;i<n->len;i++)
fwrite(&(n->msg[i]),sizeof(n->msg[i]),1,fp);
fwrite(&(n->next),sizeof(n->next),1,fp);
fclose(fp);
fp=fopen("Test.bin","rb");
if(!fp)
{
fprintf(stderr,"Error!");
return 0;
}
m=(pNode)malloc(sizeof(Node));
fread(&i,sizeof(i),1,fp);
m->len=i;
m->msg=(int*)malloc(sizeof(int)*i);
for(i=0;i<m->len;i++)
fread(&(m->msg[i]),sizeof(m->msg[i]),1,fp);
fread(&(m->next),sizeof(m->next),1,fp);
for(i=0;i<m->len;i++)
printf("%d",m->msg[i]);
//free allocated memory
}
It may have some problems, but like I said it was a long time ago.
Anyway, I hope this will help you!
GoodLuck!