08-14-2017 07:04 AM - edited 08-14-2017 07:05 AM
As the title might suggest, I am trying to write to a specific line in a text file. I have written a procedure that will initially stamp all of the credentials at the beginning of the text file. Then, it will continuously write data results into the text file over time. After the test procedure is complete, I want to stamp the finish time, but at the top of the file with all the other credentials and title "stuff" I could just post the finish time at the end of the file, but I think it would be a little cleaner to write it at the beginning.
Thanks,
Alex
Solved! Go to Solution.
08-14-2017 07:14 AM
'write' is a bit ill-defined, you can append or overwrite, not insert. What you can do is write a new file with the finish time at the beginning of the file, otherwise copying the contents of your first file, and after that delete your first file.
08-14-2017 07:22 AM
So my only option is to first make a text file holding all of the data results. Once the data results are finished, I can create a second file with the desired "title" and then copy all of the data results from the first file and paste them into the second. Afterwards, I will then delete the first file. Is this correct?
08-14-2017 07:36 AM - edited 08-14-2017 07:38 AM
Personally I think this is the safest variant. One also could keep all the data in memory until your finish time is known and thus avoid extra file activities (reading the first file, writing the second file, deleting the first file), but this might not be feasible with respect to memory requirements and / or data safety (program crash...) . Or one could use fsetpos to position the file pointer to overwrite a given portion of the file using fputs but this requires much caution.