String help!?

3 次查看(过去 30 天)
Chris
Chris 2011-12-5
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
first_guess=char(input('Enter letter \n','s'));

更多回答(1 个)

Fangjun Jiang
Fangjun Jiang 2011-12-5
use letter=input('Enter One letter: \n','s') to get the letter directly.

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by