Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Elias Gule
Elias Gule el 24 de Feb. de 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

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by