Q:

Use fgets to read strings from a file and recursively print them backwards

0

Use fgets to read strings from a file and recursively print them backwards.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now