fid = fopen('hangman.txt', 'r'); if fid < 0, error('Cannot open file.'); end CC = textscan(fid, '%s'); C = CC{1}; fclose(fid); index = ceil(rand * numel(C)); word = C{index};
stars = word; stars(~isspace(stars)) = '*';
first_guess=char(input('Enter letter \n'));
result1 = ~isempty(findstr(word,first_guess));
first_guess = 'l'; stars(original == first_guess) = first_guess;
When I try entering a letter to see if it matches one in the word, it returns an error. Enter letter l ??? Error using ==> input Undefined function or variable 'l'.

 채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2011년 12월 5일

1 개 추천

first_guess=char(input('Enter letter \n','s'));

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 12월 5일

0 개 추천

use letter=input('Enter One letter: \n','s') to get the letter directly.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by