09-24-2010 03:14 PM
Hi all
I am using the "APPEND mode (a) " while opening the file but the problem which i am facing
is that right from running the program for the first time and onwards. The data in the file
is continuously Accumulating. I want to overwrite the data in the file each time i run the
program.
What "MODE" do i have to use?
Thanks
Solved! Go to Solution.
09-24-2010 03:27 PM - edited 09-24-2010 03:29 PM
This is the exact behaviour of the append mkode: once the file is opened, the file pointer is put at file end so that new data are added to the existing file contents, which is preserved. If you want to delete previous file content you must simply open the file for writinh. In case of fopen (standard C library) it means using mode "w". In case you are using OpenFile from the Formatting and I/O Library you must use VAL_TRUNCATE keyword.
Both options are described in the online help for the functions, here and here, that you should carefully read to fully undertand their characteristics.
09-25-2010 01:14 PM
Thanks for the reply
But the "fopen" function is in the while(1) loop , i am continuously acquiring the analog signals and writing their values
to the file. If i use 'w' mode then it will write the value of the Latest iteration but i want to accumulate the values as long as the program is running and when i again run the program then the file should be over written in that case.
09-25-2010 02:30 PM
It seems to me that you are missing some very basic programming policy, independent from the instrument actually used to create an application.
Continuously opening a file (and supposedly closing it) in a loop is a very inefficient method of handling file I/O operations, since the OS have to actually put data on disk and handle closing operations and directory update on each iteration.
Unless there is some *very* special necessity to have the file permanently closed and to open it only in the moment of writing, a better policy is to open the file before the loop, perform write operations within the loop and close it after exiting the it: this permits the OS to leverage the disk buffers and to reduce slow operations to the minimum possible. With this structure you can open the file in write mode, thus deleting all existing data, and accumulate only actual data in it on every program execution.