Azzera filtri
Azzera filtri

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

4 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

KALYAN ACHARJYA
KALYAN ACHARJYA il 25 Set 2023
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 Commento
Walter Roberson
Walter Roberson il 25 Set 2023
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

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by