Hi there chelf.
Don't be so hard on yourself. You might be amazed at the number of people who come to places like this and simply post something like "PLZ Gimme The Code To Make An Accounting System With All The Bells And Whistles".
It's refreshing to see someone who's actually attempting their own code, but not too proud to ask for help. :)
I don't really have time to play with the code right now (plus I've never been very good with binary arrays, tending to use strings instead) but in concept, I'd say you're roughly on the right track. One thing to keep in mind. You don't necessarily have to write the entire file back in one go. There are other options.
For starters, just for convenience let's refer to the file as three parts. {A} is the part before where you want to delete some stuff. {B} is the part you want to delete, and {C} is the part after that. One fairly simple and efficient method would be...
- Read {A} into one array (or string).
- Read {C} into another array (or string).
- Write {A} to a new file.
- Append {C} to the new file.
This may be the fastest way, since it involves reading and writing, once only, just the data to be kept, and never even accessing the unwanted part.
Another thing to think about. It is actually possible to truncate a file (I don't remember how, though). So in theory, you should be able to simply write {C} over the top of {B}, then chop off the redundant data at the end of the file. This would be faster, but more risky.