Simplest way is to write in a new line every time.
Then loop fgets to retrieve the data, and count it or w/e you need to do with it.
: Oh i misunderstood what you are trying to do ( you wan't to delete the previous input and not leave it )
Thats even easier, you should still retrieve it with with fgets or w/e then close the file and use
fopen( sFilename, "wt" );
( This function with flags wt, deletes the content of the file ( if it exists ) and opens it for writing, also returns a handle )
Use what you retrieved previously to print whatever you need into the file
Also its good practise not to use read_file and write_file, thats why I didn't, but it would be fine to use those in your case, if you want to.