fprintf end of line character
Mostra commenti meno recenti
When I use fprintf to print multiple lines of text onto a txt file, it introduces a small rectangular box at the end of each line when ever I use '\n'. How would I print without getting that box at the end of each line of text in txt file?
Thanks, Ganesh
1 Commento
Fangjun Jiang
il 24 Mag 2011
So, what is the problem? I thought it was due to the text editor that you are using. Why does '\r\n' solve the problem?
Risposta accettata
Più risposte (4)
Jan
il 24 Mag 2011
1 voto
CHAR(10), which is the same as '\n', is a valid line break. Only the dull Windows Editor has problems with the interpretation, but this is a problem of a single outdated program. Some other editors, which can handle the line breaks correctly: The Matlab editor at least since Matlab 5.3, WordPad, Notepad++, Emacs, BBEdit, ...
Using the text mode to write files (fopen(FileName, 'wt')) has some side-effects, which may be very surprising for less experienced programmers.
Fangjun Jiang
il 24 Mag 2011
0 voti
What text editor are you using to view your text file? You need your text to appear in separated lines, right? Otherwise, you could just not to include the '\n'.
Try '\r' instead.
Walter Roberson
il 24 Mag 2011
0 voti
You should be opening your file with 'wt' instead of 'w' when you want to write text files.
Ganesh
il 24 Mag 2011
0 voti
1 Commento
Walter Roberson
il 24 Mag 2011
You should use 'at+' and then \n would work.
Categorie
Scopri di più su Characters and Strings in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!