I am experiencing problems when re-using the same file structures for different files. First open one file for reading and read its contents to memory, then close it, then reuse the same open structure to open another file, write its contents, close it. The produced file contains correct data - except every 32 bytes it contains 4 disturbing bytes. If I do not read the first file (simply jump around that piece of code), then the writing to the file is correct. Also, if I do not re-use the same structures for fileopen/fileclose/filereadwrite, then both reading and writing is correct. Is there some logical explanation of this behavior? Is it feature, do I have to allocate new structures for each file?
Example (unfortunately too long) is attached.
contains two versions with both kinds of behavior