fprintf problem printing to new line
5 views (last 30 days)
I have a problem with fprintf whereby it will not create a newline as the delimiter.
I am reading file names in from a structured array using a loop:
fid = fopen('filenameobs.txt', 'wt');
The output ends up as:
rather than each file name on a new line.
I assume the issue is my loop as examples online don't seem to have the problem but I'm unsure as to how to get around it.
Any help would be appreciated! Thanks!
Walter Roberson on 25 Mar 2013
Caution: as you opened with 'wt', if you are using MS Windows, each occurrence of \n is going to automatically replaced by \r\n, so you would end up with two \r in a row.
If you want to force \r\n always, and no sometimes-present extra \r, then fopen with 'w' instead of 'wt'.
If you want \r\n to appear or not as appropriate for the operating system, open with 'wt' and use \n instead of \r\n