Use fgets to read strings from a file and recursively print them backwards
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:10| Question number:27.10
All Answers
total answers (1)
printLinesRev.m
function printLinesRev
% Opens a file and call function to recursively
% print the lines in reverse order
% Format of call: printLinesRev or printLinesRev()
% Does not return any values
% Open file and check file open
fid = fopen('fileostrings.dat');
if fid == -1
disp('File open not successful')
else
fprtback(fid)
end
end
function fprtback(fid)
% Recursively print lines from file backwards
% Format of call: fprtback(fid)
% Does not return any values
aline = '';
if ~feof(fid)
aline = fgets(fid);
fprtback(fid)
end
disp(aline)
end
need an explanation for this answer? contact us directly to get an explanation for this answer