When you have a file open in binary mode ("r+b") via fopen(), and you're using fread() to read a sequence of structure array elements, how do you "delete" a single record (array element's contents) and replace that record with the following element's values?
Also, I've read in another post about making all sorts of changes in memory, then writing the changes to the file before closing the file pointer, but the reason why I'm failing in this task seems to be my lack of understanding of just *when* I'm supposed to incorporate fwrite() in the program.
while (count < MAXBKS && fread(&libry[count], size, 1, pbooks) == 1)
if (count == 0)
puts("Current contents of book.txt:\n");
printf("%s by %s: $%.2f\n", libry[count].title, libry[count].author, libry[count].value);
printf("Would you like to alter (a) or delete (d) this record? [Enter] for 'no'.\n");
if ((ch = getchar()) == 'd')
num = count;
libry[num] = libry[num + 1]; // this doesn't work
} // even if it did work, I have no idea how to properly use fwrite() to write
// the shorter list of records into the original file before using fclose()
Any advice would be appreciated.