필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Kratos
Kratos 2015년 2월 24일
댓글: Kratos 2015년 2월 27일
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.

채택된 답변

Elias Gule
Elias Gule 2015년 2월 24일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by