Q:

The following script calls a function getstr that prompts the user for a string, error-checking until the user enters something (the error would occur if the user just hits the Enter key without any other characters first)

0

The following script calls a function getstr that prompts the user for a string, error-checking until the user enters something (the error would occur if the user just hits the Enter key without any other characters first). The script then prints the length of the string. Write the getstr function.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ch7Ex2.m

thestring = getstr();

fprintf('Thank you, your string is %d characters long\n', ...

 length(thestring))

getstr.m

function outstr = getstr

% Prompts the user until the user enters a string

% with a length > 0

% Format of call: getstring or getstring()

outstr = input('Please enter a string: ', 's');

while isempty(outstr)

 outstr = input('PLEASE enter a string: ', 's');

end

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now