필터 지우기
필터 지우기

How to address: Invalid file identifier. Use fopen to generate a valid file identifier?

조회 수: 4 (최근 30일)
Hello,
I am trying to run the following lines but it shows error.
fid = fopen('/dev/tty', 'r');
% Display program information
fprintf(fid, '\nDetails of the program.\n');
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
I googled answer for it and understood that since fid is -1, I cannot write. But, I do not know how to solve this issue.
Any help is greatly appriciated.

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2023년 9월 25일
fid = fopen('/dev/tty', 'r');
if fid == -1
error('Failed to open /dev/tty for writing.');
end
fprintf(fid, 'Details of the program.\n')
#else
% Open for writing (r for reading)
fid = fopen('/dev/tty', 'w');
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 9월 25일
device = '/dev/tty';
if ~exist(device, 'file')
error('no file "%s"', device);
else
[fid, msg] = fopen(device, 'a+');
if fid == -1
error('Failed to open "%s" because: "%s"', device, msg);
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by