Starting a new line while writing to a text file with fprintf()
12 views (last 30 days)
Show older comments
Hello,
I'm trying to write to a text file using fprintf, and using \n to skip to a new line doesn't seems to be working. If I use something like this:
cd('C:\');
fileid=fopen('testbatfile.txt','w')
a1='@echo'
a2='cd=directory'
formatSpec = '%1s\n\r%2s\n\r';
fprintf(fileid,formatSpec,a1,a2)
My result is a text file that appears:
@echocd=directory
Why isn't '\n' working here?
Thanks in advance.
0 Comments
Accepted Answer
Walter Roberson
on 19 Apr 2012
You can open the file as 'wt' instead of 'w' and use \n instead of \n\r or you can open it the way you are now and use \r\n instead of \n\r
0 Comments
More Answers (0)
See Also
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!