From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Opening, finding, and then writing to a specific line in a text file.

Solved!
Go to solution

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

0 Kudos
Message 1 of 4
(2,731 Views)

'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.

Message 2 of 4
(2,725 Views)

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?

 

 

0 Kudos
Message 3 of 4
(2,719 Views)
Solution
Accepted by topic author Alex.Pinion

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.

Message 4 of 4
(2,714 Views)