help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Append messages to text, starting with a new line


From: zs1992
Subject: Append messages to text, starting with a new line
Date: Thu, 14 Nov 2019 01:52:12 -0600 (CST)

Hi everyone, 
I'd like to append messages to an existing text file within a loop, and each
message starts with a new line.
It seems the command "fputs" has only two input, fid and string, and every
message is appended right after the previous one. So is there any good
solution to it?

Here's part of my program.
logfile_name='log_msg.txt';
fid=fopen(logfile_name,"a");
fclose(fid);
......
for i=1:10
......
fid=fopen(logfile_name,"a");
fputs(fid,sprintf('iteration "%d" is successful',i));
fclose(fid);
endfor

the result is:
iteration "1" is successfuliteration "2" is successfuliteration "3" is
successful......

What I expected is:
iteration "1" is successful
iteration "2" is successful
iteration "3" is successful





--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]