Trying to write a function that will write my structure array to a binary file.
I thought I was able to copy it over as a complete unit one array at a time but it's not working for me.
Do I need to write each individual sub-entity or is there a way to do it in a large clump?
{
void export_binary(char *data_base_name, student_record *ptr,int array_flag,unsigned int rec_cnt)
{
if (array_flag==-99)
{
printf("\n\nDatabase not loaded...\n\nPlease IMPORT or CREATE a new database.\n\n");
system("pause");
return;
}
int rec_counter;
FILE *pf;
pf=fopen(data_base_name,"wb");
if (!pf)
{
printf("*** FILE OPENING ERROR ***\n\n");
system("pause");
return ;
}
for ( rec_counter=0; rec_counter <= rec_cnt; rec_counter++)
{
fwrite(&ptr[rec_counter], sizeof(student_record), 1, pf);
}
if ((fclose(pf))!=0)
{
printf("\n\n*** FILE Error - Closing file FAILED! ***\n\n");
system("pause");
return;
}
printf("\n\n*** Database SAVED ***");
system("pause");
return;
}