String help!?

2 visualizaciones (últimos 30 días)
Chris
Chris el 5 de Dic. de 2011
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'.

Respuesta aceptada

Chandra Kurniawan
Chandra Kurniawan el 5 de Dic. de 2011
first_guess=char(input('Enter letter \n','s'));

Más respuestas (1)

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

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by