Write a script that will prompt the user for the name of a file from which to read. Loop to error-check until the user enters a valid filename that can be opened
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:9| Question number:9.9
All Answers
total answers (1)
Ch9Ex9.m
% Prompt the user for a file name and error-check
% until the user enters a valid file name
fname = input('Enter a file name: ','s');
fid = fopen(fname);
while fid == -1
fname = input('Error! Enter a valid file name: ', 's');
end
%Error-check file close
closeresult = fclose(fid);
if closeresult == 0
disp('File close successful')
else
disp('File close not successful')
end
need an explanation for this answer? contact us directly to get an explanation for this answer