clear; clc;fid = fopen('hangman.txt','r');if fid < 0, error('Cannot open file'); enddata = textscan(fid,'%s');data = data{1};fclose(fid); index = ceil(rand * numel(data));word = data{index};masked = word; masked(~isspace(masked)) = '*';complete = 0; while complete == 0 clc; fprintf('Word : %s\n',masked); letter = (input('Guess a letter : ','s')); stat = findstr(word,letter); if ~isempty(stat) masked(stat) = letter; end if isempty(findstr(masked,'*')) complete = 1; end endclc; fprintf('Word : %s\n',masked);My letters are still case sensitive, not sure why. And I'm not sure how I could break the while loop so it stops after six incorrect guesses.
MATLAB: Strings, while loop help
strings
Best Answer