Goal:
Read and display sets of data in a binary file in struct format. Prompt for the set to be "deleted" (that is, change a value to zero). Then write that value back to the binary file.

Approach:
Open binary file. Display each set of data in a separate row, and assign each set a row number via loop and increment. When prompted which row to delete, loop through the sets until that value (increment/row number) comes up. At that point in the loop, change the old value to zero, then write the new value to the binary file.

Issue:
The value gets changed while in the delete_record( ) function (or loop anyway), but calling a report( ) function afterward to show the records in the binary file the value has not been changed; nothing was written back to the binary file.

Question:
At what point do I fwrite back to the file? I've tried within the loop and following the loops completion to no avail. It does seem weird to fwrite while in fread, but how else can I isolate that set of data, then change a value at that point?


Code:
void delete_record() 
{
	int delrow, d = 0;

	RECORDS recs;
	FILE *bf;
	company();
	printf("\t DELETE A RECORD\n\n");
	report_b();

	printf("\nEnter the row number of the product to delete: ");
	scanf_s ("%d%*c", &delrow);
	
	bf = fopen("records.dat", "rb");	
	while(fread(&recs, sizeof(recs), 1, bf))
	{
		d++;
		if (d == delrow)
		{
                        //these printf lines are for testing only
			printf("\nold prodtype  = %d",recs.prodtype),
			recs.prodtype = 0,
			printf("\nnew prodtype  = %d",recs.prodtype),
			fwrite(&recs, sizeof(recs), 1, bf);
		}
	}
        printf("\nPress [ENTER] to continue ");
	getchar();
	
	fclose(bf);
	return;
}
Any advice sages? Thanks!