% ex63.m % get word list file wname = input('Enter word list file name : ','s'); % load file and sort wtab = readtextfile(wname); swtab = sortrows(wtab); [nrows,ncols]=size(swtab); fprintf('%d words loaded from "%s"\n',nrows,wname); % open a temporary output file op=fopen('temp.txt','wt'); if (op < 0) error('could not open "temp.txt"'); end; % get the text file name tname = input('Enter text file name : ','s'); ip=fopen(tname,'rt'); if (ip < 0) error('could not open input file'); end; % load the input file as a single column txt=fscanf(ip,'%c'); fclose(ip); % convert all characters except alphabetic letters to spaces nonalphas= ~((('A' <= txt)&(txt <= 'Z'))|(('a' <= txt)&(txt <= 'z'))); txt(nonalphas)=' '; % find each word in turn [token,remainder]=strtok(txt); while (ischar(token)) if (findstring(wtab,token)==0) % not in word list, add to file of errors fprintf(op,'%s\n',token); end; % get next word in rest of text [token,remainder]=strtok(remainder); end; fclose(op); % load in file of mis-spelled words etab = readtextfile('temp.txt'); % get a list of unique rows (also sorts the list) ewords = unique(etab,'rows'); % display mis-spelled words fprintf('These words are mis-spelled:\n'); disp(ewords);