Do you need
insert or
overwrite, because these two things are different.
When you open the file with fopen(), use mode "w+"
Quote
Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
If you want to overwrite, after you read the record, you can back up and write a new one using fseek(), like this:
// Assuming 4 byte integers. ptr is a pointer to an integer. fp is a file pointer.
fread(ptr, 4, 1, fp);
// Back up one record
fseek(fp, -4, SEEK_CUR);
// Edit the value of ptr and overwrite the record
fwrite(ptr, 4, 1, fp);
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid