% ex62.m % ask for question file name qname = input('Enter file containing questions : ','s'); % create a log file based on that name lname = [ qname '.log' ]; % open the input file ip = fopen(qname,'rt'); if (ip < 0) error('could not open input file'); end; % open the output file op = fopen(lname,'wt'); if (op < 0) error('could not open output file'); end; % ask each question in turn q = fgetl(ip); while (ischar(q)) fprintf('%s\n',q); a = input('Answer T(rue) or F(alse) : ','s'); while ((a~='T')&(a~='F')) a = input('Answer T(rue) or F(alse) : ','s'); end; fprintf(op,'%s\nAnswer: %s\n',q,a); q = fgetl(ip); end; fclose(ip); fclose(op);