필터 지우기
필터 지우기

add a line to a text file without fprintf?

조회 수: 2 (최근 30일)
Constance Woodman
Constance Woodman 2017년 7월 27일
편집: Walter Roberson 2017년 7월 27일
So, when adding lines to text files I always see
fid = fopen(fileName,'w');
fprintf(fid,'%s\n','content');
fclose(fid);
Can this be done without fprintf, to avoid spending system resources displaying text command window? Or is it somehow necessary to see the text in the command window when writing to a file?

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 27일
편집: Walter Roberson 2017년 7월 27일
? That code would not display anything to the command window.
fprintf(fid,...) displays to the command window only if the fid is exactly 1 or exactly 2, and neither of those values will ever be returned by fopen().
But to answer your question:
S = sprintf('%s\n','content');
fid = fopen(fileName,'w');
fwrite(fid, S);
fclose(fid);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by