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.
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.
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.
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?
Any advice sages? Thanks!
int delrow, d = 0;
printf("\t DELETE A RECORD\n\n");
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))
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 ");