To avoid losing the data, you need to periodically close and reopen the file. In most applications where I'm taking measurements over a long period of time, I take my measurement, open the file for append, write the data, then close the file.
How often do you need to sample the data? Today's hard disks are typically very fast compared to how often most applications take measurements.
If you have multiple users accessing the same file, you have several options including:
1. Create a database application that supports record locking and file sharing. You could use Access, SQL Server, or Oracle, etc., and ActiveX.
2. Write your application to use fopen() to open the file for append, write the data, and close the file. Put fopen in a loop with a timeout. If a user enco
unters an error opening the file (because another user is writing to the file), stay in the loop and try again until a timeout occurs. When the first user closes the file, the second will be able to open it with no errors.