function read_file(filename) % % Read the contents of the given file. % Print out each line from the file onto the screen. % % Arguments: % % filename (input) name of disk file to read % % first, we try to open the file for reading fid = fopen(filename, 'r'); if (fid == -1) error('read_file: cannot open file for reading'); end % read each line from the file, printing it to the screen as we go done_yet = 0; while (done_yet == 0) line = fgets(fid); if (line == -1) done_yet = 1; else % we don't need to add an '\n' at the end, because the FGETS % function keeps the newline at the end of the string it returns. fprintf(1, '%s', line); end end % remember to close the file before we return; fclose(fid);