Azzera filtri
Azzera filtri

How do I ignoring '\n' at the end of the text file that was created?

1 visualizzazione (ultimi 30 giorni)
Hello I created a text file called phonenumbers using the strings that gave true for the condition that I set. I used
fprintf(output, '%s\n', line);
to print it on the output file. The only problem is when I compare the file I created with the solution file, I get one extra new line at the end of the file. I am only suppose to have 11 lines but I get 12 lines. How do I fix it. I also have a screenshot below.
Thank you.

Risposta accettata

Elias Gule
Elias Gule il 24 Feb 2015
You are appending that extra line. What you can do is change:
fprintf(output,'%s\n',line)
to
fprintf(output,'\n%s',line)
after adding the first line using
fprintf(output,'%s',line)
Example Code:
lines = {'firstPhoneNumber','secondPhoneNumber','thirdPhoneNumber'};
for k = 1 : length(lines)
line = lines{k};
if(k==1)
fprintf(output,'%s',line);
else
fprintf(output,'\n%s',line);
end
end

Più risposte (0)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by