Originally Posted by Darryl
Are you zeroing out the buffer after each read, because here is what I suspect is happening.
You read in 9999, write it, read in another 9999 overwriting old data. Now when it gets to the leftovers at the end of the file that is less that 9999, (for instances, let's say 100), it's reading those 100 and overwriting the first 100 of the last 9999. Thus when you look at the end of what you wrote you are thinking, where is the end of my data? (it's at the beginning of this 9999 block)
I believe read returns number of bytes read, you could use that number to place your terminating null instead of just blindly at 9999, that way the last read will work... or you can 0 out in between, but that will be a little slower.