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.