Ok I have a linked list which have to read from binary file and to write in binary files.
This is the function about the reading from keyboard:

short readElement( Node * newE)
{ 	int b,e,m;
  	if ( newE == NULL ) return 1;
  	do {
		printf("\n Registration number:");
			scanf("%s", &newE->regnomer);
		printf("\n Brand:");
			scanf("%s", &newE->marka);
		printf("\n Year:");
			b = scanf("%d",  &newE->godina );
		printf("\n Kilometres:");
			e = scanf("%d",  &newE->kilometri );
		printf("\n Passengers:");
					m = scanf("%d",  &newE->mesta );
		fflush(stdin);
		if ( b == EOF ) return 1;
		if(dostovernost(newE))
			printf("\nWrong input!");
	} while(dostovernost(newE));
	writebinary(newE,fout);
	return 0;
}

writebinary is the function about writing the binary file:

short writebinary(Node *curE,FILE *fout)
{
	int k,l,m,n,p;
	if ( curE == NULL ) return 1;
	if ( fout == NULL) return 2;
	k = fwrite( &curE->regnomer, sizeof(Node), 1, fout );
	l = fwrite( &curE->marka, sizeof(Node), 1, fout );
	m = fwrite( &curE->godina, sizeof(Node), 1, fout );
	n = fwrite( &curE->kilometri, sizeof(Node), 1, fout );
	p = fwrite( &curE->mesta, sizeof(Node), 1, fout );
	if ( k == 1 && l==1 && m==1 && n==1 && p==1 ) return 0;
	return 3;
}

After testing the program it gaves a binary file with some size but I'm not sure the function is absolutely right.
This is the file pointer

FILE *fout=fopen("binar.dat","w");

I'll be happy to be given some code about reading the completed binary file in humanly readable format, and to have function which reads binary data in the linked list. My last question is about the given code. Is it right? Best regards.

Here is short program demonstrating how to read and write data from binary file using structure I don't the structure so I use my own simple structure change this to your on structure

#include<stdio.h>
#include<conio.h>

struct NODE
{
int roll_no;
char name[30];
};
void write_binary(FILE *f1)
{
struct NODE s;
printf("Enter Name : ");
scanf("%s",s.name);
printf("Enter Roll no. : ");
scanf("%d",&s.roll_no);
fwrite(&s, sizeof(s), 1, f1); /* write struct s to file */
}
void read_binary(FILE *f1)
{
struct NODE s;


	while(fread(&s, sizeof(s), 1, f1))
	{
	printf("\nName : %s",s.name);
	printf("\nRoll No.: %d",s.roll_no);

	}
}
void main()
{
FILE *f1;
clrscr();
f1=fopen("binary.dat","wb");
write_binary(f1);
write_binary(f1);
fclose(f1);
f1=fopen("binary.dat","rb");
read_binary(f1);
getch();
}

Actually I did not understand why you use all this extra variable l,m,n,p just this simple function.
What ever I think your main problem is reading and writing structure variable into binary file.
Which show to you
Best Of Luck.

Sorry actually in my first post I did't able to understand your problem and I post simple read and write binary file function
Here is a Program which show how to read and write LINK LIST DATA into Binary file

#include<stdio.h>
#include<conio.h>

struct data
{
int roll_no;
char name[30];
};

struct NODE
{
struct data d1;
struct NODE *next;
};

struct NODE *head=NULL,*head1=NULL;
void insr(struct data d);

void write_binary(FILE *f1)//writing linked list to file
{
struct data s;
head1=head;
	while(head!=NULL)
	{
	s=head->d1;//.name;
	fwrite(&s, sizeof(s), 1, f1); /* write struct s to file */
	head=head->next;
	}
}

void read_binary(FILE *f1)//reading binary file into link list
{
struct data s;
head=NULL;
	while(fread(&s, sizeof(s), 1, f1))
	{
	insr(s);
	}
}


void insr(struct data d) //Inserting structure data into linked list
{
struct NODE *p;
p=(struct NODE*)malloc(sizeof(struct NODE));
p->d1=d;
if(head==NULL)
p->next=NULL;
else
p->next=head;
head=p;
}

void disp()
{
printf("Name\t\tRoll No.\n");
while(head!=NULL)
	{
	printf("\n%s\t\t%d",head->d1.name,head->d1.roll_no);
	head=head->next;
	}

}
void main()
{
FILE *f1;
struct data d;
int i=0;
clrscr();
for(i=0;i<5;i++)
{
printf("\nName : ");scanf("%s",d.name);
printf("Roll No : ");scanf("%d",&d.roll_no);
insr(d);
}
f1=fopen("binary.dat","wb");
write_binary(f1);
fclose(f1);
f1=fopen("binary.dat","rb");
read_binary(f1);
fclose(f1);
disp();
getch();
}

I don't have your data structure so I use own simple structure, one structure for link list and another for data.

Any way try to lean..............
Best5 Of Luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.